-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(react): Fix incorrect extensionAttributes value #5588
Conversation
🦋 Changeset detectedLatest commit: 9ddc31b The changes in this PR will be included in the next version bump. This PR includes changesets to release 54 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
const extensionAttributes = this.editor.extensionManager.attributes.filter( | ||
attribute => attribute.type === this.node.type.name, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, what did you run into that warrants this change? It is not clear to me why it is needed? It feels like something that is better placed as a responsibility of getRenderedAttributes
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "attrs" function would accept all extensions' acttributes, it wasn't what i expected, it only need accpet relative extensions' acttributes. Maybe there's a better way to write it that I don't know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, you are right here. I just think it is better implemented in the function getRenderedAttributes
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I normally would just apply my patch on top of the branch, but some reason it was disabled, so here is the patch I would apply to this PR
diff --git a/packages/core/src/helpers/getRenderedAttributes.ts b/packages/core/src/helpers/getRenderedAttributes.ts
index 5dd0855a2..fd85e699a 100644
--- a/packages/core/src/helpers/getRenderedAttributes.ts
+++ b/packages/core/src/helpers/getRenderedAttributes.ts
@@ -8,6 +8,9 @@ export function getRenderedAttributes(
extensionAttributes: ExtensionAttribute[],
): Record<string, any> {
return extensionAttributes
+ .filter(
+ attribute => attribute.type === nodeOrMark.type.name,
+ )
.filter(item => item.attribute.rendered)
.map(item => {
if (!item.attribute.renderHTML) {
diff --git a/packages/react/src/ReactNodeViewRenderer.tsx b/packages/react/src/ReactNodeViewRenderer.tsx
index 054b69130..4f16c0c8c 100644
--- a/packages/react/src/ReactNodeViewRenderer.tsx
+++ b/packages/react/src/ReactNodeViewRenderer.tsx
@@ -304,9 +304,7 @@ export class ReactNodeView<
let attrsObj: Record<string, string> = {}
if (typeof this.options.attrs === 'function') {
- const extensionAttributes = this.editor.extensionManager.attributes.filter(
- attribute => attribute.type === this.node.type.name,
- )
+ const extensionAttributes = this.editor.extensionManager.attributes
const HTMLAttributes = getRenderedAttributes(this.node, extensionAttributes)
attrsObj = this.options.attrs({ node: this.node, HTMLAttributes })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's great! But i am not sure if it will break the previous features?
Changes Overview
Prevent to call renderHTML function of all extensions.
Implementation Approach
Testing Done
Verification Steps
Additional Notes
Checklist
Related Issues