Edit Site: Move loading logic to a separate hook#50511
Conversation
|
Size Change: +4 B (0%) Total Size: 1.38 MB
ℹ️ View Unchanged
|
youknowriad
left a comment
There was a problem hiding this comment.
LGTM 👍 Thanks for the follow-up.
|
Flaky tests detected in b92c69b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4938075397
|
54176ac to
b92c69b
Compare
jsnajdr
left a comment
There was a problem hiding this comment.
Looks good now, I'm suggesting one more little improvement and that should be all.
| return { | ||
| hasResolvingSelectors: select( coreStore ).hasResolvingSelectors(), | ||
| }; | ||
| } ); |
There was a problem hiding this comment.
One more optimization opportunity: this useSelect will return a new value every time any selector starts or stops resolving, even long after the editor is fully loaded. That will trigger a rerender of the Editor component that uses the useIsSiteEditorLoading hook.
You can make the return value more stable by including the loaded value as dependency:
const [ loaded, setLoaded ] = useState( false );
const inLoadingPause = useSelect( ( select ) => {
const hasResolvingSelectors = select( coreStore ).hasResolvingSelectors();
return ! loaded && ! hasResolvingSelectors;
}, [ loaded ] );This will guarantee a stable false return value once the loaded state is achieved. No more renderers.
There was a problem hiding this comment.
Good catch, I'll follow up in another PR.
What?
This PR is a follow-up to #50222 (comment) and moves the site editor loading logic to a separate hook.
Why?
Helps abstract the loading logic from the
Editorcomponent and improve readability.How?
We're moving the logic to a hook and keeping the logic unchanged.
Testing Instructions
Same as testing instructions of #50222.
Testing Instructions for Keyboard
None
Screenshots or screencast
None