-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Iframe: event bubbling should retain the original target #55105
Conversation
Size Change: +17 B (0%) Total Size: 1.65 MB
ℹ️ View Unchanged
|
// inadvertantly (like global shortcuts when typing within inputs...) | ||
Object.defineProperty( newEvent, 'target', { | ||
writable: false, | ||
value: event.target, |
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 guess that makes sense, the React events also have the original target
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.
But it doesn't work unfortunately. It breaks shortcuts like the "duplicate block" one and I'm not sure how to fix.
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 think we should re-explore the provider tbh, and avoid this bubbling entirely.
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 agree that there's something to be reconsidered here but I don't know yet what the solution is. I think a provider like we used to have is a hack. It relies on React event bubbling working but not DOM events) which means we won't be able to have global shortcuts).
I'm thinking maybe we could have a special provider wrapping the iframe body content, but I'm not entirely sure how that would work.
What?
In #54080 we changed how we capture keyboard shortcuts and in doing so we added keydown events bubbling to the editor iframe component.
One side effect I noticed was that in "playground" in storybook, when typing in the editor, typed characters conflicted with Storybook shortcuts. The weird thing is that even if there were no iframe used (so events are still bubbling on the same window), the conflicts didn't happen. So the issue was in the way we generated the "virtual" events in the iframe component (since in both with or without iframe, the event was propagated to the parent of the editor).
After multiple checks and attempts, it seems that copying the "target" property (which is supposed to be readonly) when creating the synthetic event is what was triggering the conflict. Some event handlers ignore events from inputs/contenteditable...
Let's see if the e2e tests of Gutenberg confirm the fix or not.
Testing Instructions
1- Run storybook locally
npm run storybook:dev
2- Open one of the playground stories
3- Type "s" within the editor, the Storybook sidebar shouldn't be toggling.