-
Notifications
You must be signed in to change notification settings - Fork 2k
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
FSE: Fix missing inserter #44357
FSE: Fix missing inserter #44357
Conversation
Caution: This PR affects files in the FSE Plugin on WordPress.com D46774-code has been created so you can easily test it on your sandbox. See this FieldGuide page about developing in the FSE Plugin for more info: PCYsg-ly5-p2 |
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
// Re-inject the FSE inserter as needed in case React re-renders the header | ||
const wpbody = document.getElementById( 'wpbody' ); | ||
if ( wpbody && typeof window.MutationObserver !== 'undefined' ) { | ||
const observer = new window.MutationObserver( injectBlockInserter ); |
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.
Clever workaround! I learned something new today, didn't know about the MutationObserver
API.
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.
Clever workaround!
Agreed! I didn't know about the MutationObserver
either, this is very interesting and great to see. Nice work here. 😄
Why should it not be present on the page editor? |
It's hidden on the page editor so that it can be replaced with a custom inserter. That's part of the dotcom-fse functionality. I don't know many details about why 🙂 |
Works great ✔️
|
Interesting. Not critical or anything, but I'd love to know why a custom inserter is needed there and what it does differently cc @noahtallen |
If I remember correctly:
|
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.
Testing this on my FSE site and it looks good!
I didn't realize that the inserter was also being hidden in the post editor but only re-added in the page editor. 🤦♀️ So the inserter must have been missing from the post editor for quite some time?
Either way, with this PR the inserter is back in both editors and working well on both (edge and non-edge) Gutenberg versions.
Great job, and thank you for fixing this!
Although a separate issue, it's worth noting that the inserter is different between the post and page editors. Since the post editor is not re-implementing the inserter we have the standard sidebar style inserter with the patterns tab. While in the page editor our re-implemented version is the dropdown inserter for blocks only. This is expected with the current implementation and is in the prioritized backlog of the gardening board (#41654).
Thanks, folks!
That seems to be the case. I discovered it when I started looking at #43784. |
Changes to |
Changes proposed in this Pull Request
Add a MutationObserver to re-inject a React component on DOM changes if the component is not already present.
This is a workaround for #43784, which observed that the component is missing. The component is injected into a React tree, which is volatile. Injected components like this will disappear if a parent is re-rendered.
This also adds a class to fix the block inserter from being removed from the post editor. It should only be removed from the page editor.
Testing instructions
Use a dotcom-fse enabled site for testing.
Fixes #43784