-
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
Automatically use a subregistry when using the block editor provider #14678
Conversation
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 haven't tested but it all looks good. I"m a little bit behind all the latest refactorings in this area though :)
packages/block-editor/src/components/provider/with-registry-provider.js
Outdated
Show resolved
Hide resolved
} | ||
|
||
useEffect( () => { | ||
const newRegistry = createRegistry( {}, registry ); |
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.
It took me a while to understand what's happening here:
- so it creates a new registry and points the passed registry as a parent
- overrides
core/block-editor
- does some magic with middlewares
} | ||
|
||
useEffect( () => { | ||
const newRegistry = createRegistry( {}, registry ); |
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 it work as well?
const newRegistry = createRegistry( {}, registry ); | |
const newRegistry = createRegistry( { 'core/block-editor': storeConfig }, registry ); |
This is what I read from:
https://github.com/WordPress/gutenberg/blob/master/packages/data/src/registry.js#L181
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, previously this was not possible because the controls plugins was not built-in but we can do this now. Good suggestion.
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.
Oh I guess we still can't do that yet because we need the returned "store" object to apply middlewares.
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.
This all is pretty confusing to me 😅 Part of that is being new. Wonder if we should be looking to bring in |
} | ||
|
||
useEffect( () => { | ||
const newRegistry = createRegistry( {}, registry ); |
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.
packages/block-editor/src/components/provider/with-registry-provider.js
Outdated
Show resolved
Hide resolved
A thought occurs to me: Would we want to do something similar for EditorProvider ? Thinking for how separately I've proposed to use it for reusable blocks . If so, is there a concern about all these nested registries? Or would it scale reasonably well? |
I think we should yes, about the scaling, it's a good question that I can't answer :). I'd say that the overhead of a new registry is pretty small based on how it works but I have no proof. |
This PR automatically creates a subRegistry for each block editor provider making it more like "local state" and making the component more reusable.
We opt-out from this behavior using
useSubRegistry={ false }
in the edit-post module in order to allow access to thecore/block-editor
store from the global registry in the editor page. (BC)Testing instructions
wp.data.select( 'core/block-editor' ).getBlocks()