Skip to content
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

Partial support for React.lazy() in server renderer. #16383

Merged
merged 1 commit into from
Aug 14, 2019

Conversation

leebyron
Copy link
Contributor

@leebyron leebyron commented Aug 13, 2019

Provides partial support for React.lazy() components from the existing PartialRenderer server-side renderer.

Lazy components which are already resolved (or rejected), perhaps with something like react-ssr-prepass, can be continued into synchronously. If they have not yet been initialized, they'll be initialized before checking, opening the possibility to exploit this capability with a babel transform. If they're pending (which will typically be the case for a just initialized async ctor) then the existing invariant continues to be thrown.

@sizebot
Copy link

sizebot commented Aug 13, 2019

Warnings
⚠️

Base commit is broken: 21d6395

Generated by 🚫 dangerJS

Provides partial support for React.lazy() components from the existing PartialRenderer server-side renderer.

Lazy components which are already resolved (or rejected), perhaps with something like `react-ssr-prepass`, can be continued into synchronously. If they have not yet been initialized, they'll be initialized before checking, opening the possibility to exploit this capability with a babel transform. If they're pending (which will typically be the case for a just initialized async ctor) then the existing invariant continues to be thrown.
@sebmarkbage
Copy link
Collaborator

I noticed you removed the enableSuspenseServerRenderer branch. Any particular reason for that? It seemed ok.

export function initializeLazyComponentType(
lazyComponent: LazyComponent<any>,
): void {
if (lazyComponent._status === Uninitialized) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could be a breaking change if this was using a non-matching version of React. That was the case in React 16.5.0 where this field was called _reactStatus. In this case I that release had lazy behind a feature flag. So iit's probably fine.

We typically are more resilient and check truthy or non-undefined or something like that and then add an expando in that case so that it at least works.

@sebmarkbage sebmarkbage merged commit 5663635 into facebook:master Aug 14, 2019
@leebyron
Copy link
Contributor Author

For the enableSuspenseServerRenderer branch, I wasn’t sure of the right behavior or test plan and figured it would be better to keep this one smaller and follow up with that change in another PR after this one

gaearon pushed a commit to gaearon/react that referenced this pull request Aug 14, 2019
Provides partial support for React.lazy() components from the existing PartialRenderer server-side renderer.

Lazy components which are already resolved (or rejected), perhaps with something like `react-ssr-prepass`, can be continued into synchronously. If they have not yet been initialized, they'll be initialized before checking, opening the possibility to exploit this capability with a babel transform. If they're pending (which will typically be the case for a just initialized async ctor) then the existing invariant continues to be thrown.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants