-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Updating ReactNodeViewRenderer element's attributes when the node updates #5494
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
Updating ReactNodeViewRenderer element's attributes when the node updates #5494
Conversation
🦋 Changeset detectedLatest commit: 3b83b28 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. |
Hi, appreciate your contribution here. Forgive me, but I'm having a hard time understanding what this resolves. Could you maybe add an example (codesandbox or even just in the repo is fine) to help me understand what exactly this is resolving? Sorry to make you do more work, but I have to understand it before I can merge it |
@nperez0111 I want to set a data attributes in the "react-render" div element using global attributest like "data-sid", but it doesn't update when attrs.sid was updated https://codesandbox.io/p/sandbox/cocky-jang-vdfw46 Also you can see this issue #4239, I think it will be solved by using this solution
|
if (attrs) { | ||
Object.keys(attrs).forEach(key => { | ||
this.element.setAttribute(key, attrs[key]) | ||
}) | ||
} | ||
|
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 would prefer to keep this updating of the element within the ReactRenderer rather than have the ReactNodeViewRenderer
managing it.
Could we add a method here that basically does this code here, named updateAttributes
which ReactNodeViewRenderer
calls when it wants to apply the changed attributes.
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.
Good advice, thank you!
Object.keys(attrsObj).forEach(key => { | ||
this.renderer.element.setAttribute(key, attrsObj[key]) | ||
}) |
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.
Would prefer to call into the ReactRenderer here so we keep these separated
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.
Please review again~ @nperez0111
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.
Thanks for explaining & the code sandbox. I like this, just a minor nitpick
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.
LGTM
Updating ReactNodeViewRenderer element's attributes when the node updates to fix #4239
Changes Overview
Supporting function type for attrs option of ReactNodeViewRendererOptions to obtain latest attributes.
Implementation Approach
Testing Done
Verification Steps
"count" attribute will real time update

Checklist
Related Issues