-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Edit Site: Move loading logic to a separate hook #50511
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
Conversation
|
Size Change: +4 B (0%) Total Size: 1.38 MB
ℹ️ View Unchanged
|
youknowriad
left a comment
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I'll follow up in another PR.
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.
See #50546
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