-
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
Improve Slot/Fill performance #44642
Conversation
Size Change: +2.28 kB (0%) Total Size: 1.27 MB
ℹ️ View Unchanged
|
So this indeed solves the issue but there's a few test failures that I need to address as well (tomorrow) |
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 digging into this rabbit role! It'd be easier to review if there are some comments or some detailed technical explanations in the PR description though 😅 .
* External dependencies | ||
*/ | ||
import { ref as valRef } from 'valtio'; | ||
import { proxyMap } from 'valtio/utils'; |
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.
Any reason why we want to introduce yet another package here to solve this issue? Is it too tedious to solve in vanilla React?
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.
Yes, I found it a bit difficult (also a lot of code) to recreate the same behavior with only React. Basically we'd want multiple event emitters, we want to subscribe to changes for each slot separately and each fills for a slot.
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, I accidentally marked this as resolved.
packages/components/src/slot-fill/bubbles-virtually/slot-fill-provider.js
Show resolved
Hide resolved
@youknowriad I think there might be a small regression. Sometimes when a block is selected, empty slots are rendering on the toolbar: It's a little inconsistent to reproduce. These steps seem to work:
|
Was going to report this one |
Nice work here! |
@youknowriad, do we publish dev notes for experimental APIs? I believe this is a breaking change for third-party code using Directory search: https://wpdirectory.net/search/01GPDJDZ7CA9W122V0ENRCA0T0 The problem was initially reported by the CoBlocks team. Example code that will break: function ExampleSlot( { children } ) {
const slot = useSlot( slotName );
const hasFills = Boolean( slot.fills && slot.fills.length );
if ( ! hasFills ) {
return children;
}
// return the actual slot;
return null;
} |
Yeah, at the time of this PR, |
What?
This PR #42722 introduced a regression in performance for block selection and inserter opening, after some debugging, I found that the main issue is that the popover components are being re-rendered synchronously even if they're actually inside "Async mode".
The reason is because they're not being re-rendered due to a "store change" (which is impacted by async mode) but because a new fill is being added or removed on each block selection which calls the
SlotFillContext
to update its value causing a re-render for any component callinguseSlot
, including all popovers.How?
This PR solves this by making
SlotFillContext
value stable across addition and removals of slot/fills and by using "valtio" library to be able to subscribe individually to a given slot name or fills for a given slot name. It also does so by introducing a new hook called useSlotFills which only gives you the "fills" of a given slot.Testing Instructions
1- Mainly check the results of the performance jobs.