-
Notifications
You must be signed in to change notification settings - Fork 47k
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: SVG with dangerouslySetInnerHTML content does not trigger first #31038
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Comparing: d2e9b9b...de12a4a Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) |
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.
Thank you. This doesn't fix the issue though. The code in react-devtools-shared
is unrelated to the react
or react-dom
packages.
I suspect the test is only passing because of some JSDOM quirks.
Thanks @eps1lon I made some progress with this. Check out this screenshot: Found this little TODO in the onClick case in ReactDOMComponent.js which I suspected might be the reason. I wrote to pretty comprehensive test to verify the correct handling of the onClick event for SVG elements with dangerouslySetInnerHTML The test uses React's internal setInitialProperties and updateProperties functions to mimic real rendering behavior. It fails if the innerHTML isn't set correctly or if click handlers aren't called as expected, helping identify issues with event handling on SVG elements. Essentially, It mocks the DOM methods that can't be relied on in JSDOM.
Note: I will remove the console logs Thankfully, this test failed in the first run. Output:
Thus, I decided to work on my suspected TODO. Updated it from this:
To this:
And here are the test results for this fix:
Committing changes now. |
The tests uses too many implementation details. A codesandbox from https://react.new is sufficient to verify this works. You can verify with builds from the branch in the GitHub status check "ci/codesandbox" e.g. for this commit https://ci.codesandbox.io/status/facebook/react/pr/31038/builds/545160 |
Oh wow, thanks for this. This makes things so much easier. Let me make a few commits and test around with a few builds before I ask you for another review. Thanks so much @eps1lon ! |
Summary
I have managed to find a fix for the issue #30994
Inside the Element.js component:
How did you test this change?
Here is the test case I wrote to test my changes:
in src/tests/ReactDOMSVG-test.js:
Output:
And here are the results after running the test:
This test essentially spins up an SVG with a dangerouslySetInnerHTMLm, and attempts to simulate a click event on it.