Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

⚛️ Use Suspense and lazy to Hydrate views that were not registered before calling hydrate() #78

Conversation

DAreRodz
Copy link
Collaborator

Coauthored with @c4rl0sbr4v0

This PR replaces the Map we used to store the View components with an object with a similar API. The difference is that the method get returns a promise that resolves once the View component is registered.

With that Promise, we can use Suspense and lazy to pause hydration until the components are ready.

Copy link
Member

@luisherranz luisherranz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🙂👏

Note for the future: if we want to use async, this code needs to be included in each bundle. To save some bytes on each bundle, I think we could find a way to move the promise-related logic to the hydration file instead. But this is perfect for now, thanks folks! 🎉

@luisherranz luisherranz merged commit 7c1ddb9 into main-full-vdom-hydration Sep 29, 2022
@luisherranz luisherranz deleted the full-vdom/view-hydration-after-dom-node-appears branch September 29, 2022 12:03
@DAreRodz
Copy link
Collaborator Author

That was fast!! 😆 🚀

@DAreRodz DAreRodz changed the title Use Suspense and lazy to Hydrate views that were not registered before calling hydrate() ⚛️ Use Suspense and lazy to Hydrate views that were not registered before calling hydrate() Sep 29, 2022
@michalczaplinski
Copy link
Collaborator

Nice work 👏

It's very similar to the work Bernie and me did in Woo-BHE to solve the problem of hydrating blocks when their views get registered too late:

woocommerce/woocommerce-blocks-hydration-experiments@8edc7b2

We ended up not using that code in the end because the problem because there was a simpler solutionat the time.

@DAreRodz
Copy link
Collaborator Author

DAreRodz commented Oct 3, 2022

Hey @michalczaplinski, I wasn't aware of that code! I see it's very similar, although it's using a Proxy to detect the Component's registration. Thanks for sharing it. 😊

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants