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

[Blocks] Make it possible to have lazy initialized and lazy loaded Blocks #18220

Merged
merged 3 commits into from
Mar 6, 2020

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Mar 5, 2020

This builds on a similar design as Lazy in #18217

The goal here is to make evaluating the query lazy but still allow render functions from different sources to reconcile against each other - even if they're lazy. In my first approach I hid the lazy loading into the "render" function wrapper which is not going to work since it doesn't reconcile against the same thing anymore then.

Blocks now initialize lazily.
This is for the case when it's a new Block that hasn't yet initialized.
We need to first initialize it to see what "render function" it resolves
to so that we can use that in our comparison.
@facebook-github-bot facebook-github-bot added React Core Team Opened by a member of the React Core Team CLA Signed labels Mar 5, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 5, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit db9c751:

Sandbox Source
adoring-feather-fde9g Configuration

@sizebot
Copy link

sizebot commented Mar 5, 2020

Details of bundled changes.

Comparing: fa03206...db9c751

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js +0.3% +0.2% 123.84 KB 124.16 KB 38.64 KB 38.73 KB NODE_PROFILING
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 58.91 KB 58.91 KB 14.71 KB 14.71 KB UMD_DEV
ReactDOM-dev.js +0.2% +0.2% 897.53 KB 899.21 KB 200.61 KB 200.93 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.27 KB 10.27 KB 3.49 KB 3.5 KB UMD_PROD
ReactDOMServer-dev.js 0.0% -0.0% 137.25 KB 137.25 KB 35.06 KB 35.06 KB FB_WWW_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 10.96 KB 10.96 KB 4.17 KB 4.17 KB UMD_PROD
ReactDOMTesting-dev.js +0.2% +0.2% 872.76 KB 874.43 KB 195.47 KB 195.79 KB FB_WWW_DEV
ReactDOMTesting-prod.js 🔺+0.3% 🔺+0.3% 368.74 KB 369.8 KB 67.46 KB 67.67 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% -0.0% 49.56 KB 49.56 KB 13.52 KB 13.52 KB NODE_DEV
ReactDOMTesting-profiling.js +0.3% +0.3% 368.74 KB 369.8 KB 67.46 KB 67.67 KB FB_WWW_PROFILING
react-dom-server.node.development.js 0.0% 0.0% 131 KB 131 KB 34.81 KB 34.81 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 10.81 KB 10.81 KB 4.1 KB 4.1 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% 0.0% 20.83 KB 20.83 KB 7.61 KB 7.61 KB NODE_PROD
react-dom.development.js +0.2% +0.2% 912.84 KB 914.63 KB 199.76 KB 200.08 KB UMD_DEV
react-dom-server.browser.development.js 0.0% 0.0% 136.78 KB 136.78 KB 34.96 KB 34.96 KB UMD_DEV
react-dom.production.min.js 🔺+0.3% 🔺+0.3% 119.89 KB 120.21 KB 38.28 KB 38.4 KB UMD_PROD
react-dom-server.browser.production.min.js 0.0% 0.0% 20.51 KB 20.51 KB 7.51 KB 7.51 KB UMD_PROD
react-dom.profiling.min.js +0.3% +0.2% 123.54 KB 123.86 KB 39.47 KB 39.54 KB UMD_PROFILING
react-dom.development.js +0.2% +0.2% 868.91 KB 870.6 KB 197.31 KB 197.64 KB NODE_DEV
react-dom-server.browser.development.js 0.0% 0.0% 129.78 KB 129.78 KB 34.55 KB 34.55 KB NODE_DEV
react-dom.production.min.js 🔺+0.3% 🔺+0.2% 120.04 KB 120.36 KB 37.52 KB 37.6 KB NODE_PROD
react-dom-server.browser.production.min.js 0.0% 0.0% 20.43 KB 20.43 KB 7.46 KB 7.46 KB NODE_PROD
ReactDOM-prod.js 🔺+0.3% 🔺+0.3% 370.72 KB 371.78 KB 67.55 KB 67.77 KB FB_WWW_PROD
ReactDOMServer-prod.js 0.0% 0.0% 46.78 KB 46.78 KB 10.87 KB 10.87 KB FB_WWW_PROD
ReactDOM-profiling.js +0.3% +0.3% 381.98 KB 383.04 KB 69.67 KB 69.88 KB FB_WWW_PROFILING
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 55.87 KB 55.87 KB 14.47 KB 14.47 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 3.69 KB 3.69 KB 1.34 KB 1.34 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10 KB 10 KB 3.37 KB 3.38 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.2% 1.16 KB 1.16 KB 662 B 663 B NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 3.35 KB 3.35 KB 1.27 KB 1.27 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.4% 1.19 KB 1.19 KB 697 B 700 B UMD_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 2.95 KB 2.95 KB 1.18 KB 1.18 KB NODE_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1 KB 1 KB 609 B 611 B NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.3% +0.2% 634.18 KB 635.96 KB 133.2 KB 133.49 KB UMD_DEV
react-art.production.min.js 🔺+0.3% 🔺+0.3% 106.64 KB 106.97 KB 32.25 KB 32.34 KB UMD_PROD
react-art.development.js +0.3% +0.3% 538.39 KB 540.08 KB 115.6 KB 115.91 KB NODE_DEV
react-art.production.min.js 🔺+0.4% 🔺+0.4% 71.62 KB 71.94 KB 21.44 KB 21.53 KB NODE_PROD
ReactART-dev.js +0.3% +0.3% 541.98 KB 543.66 KB 113.71 KB 114.02 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.5% 🔺+0.5% 226.66 KB 227.72 KB 38.52 KB 38.73 KB FB_WWW_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler-reflection.development.js 0.0% 0.0% 16.25 KB 16.25 KB 4.97 KB 4.97 KB NODE_DEV
react-reconciler-persistent.production.min.js 0.0% 0.0% 73.73 KB 73.73 KB 21.78 KB 21.78 KB NODE_PROD
react-reconciler-reflection.production.min.js 0.0% 🔺+0.2% 2.81 KB 2.81 KB 1.21 KB 1.21 KB NODE_PROD
react-reconciler.development.js +0.3% +0.3% 576.69 KB 578.38 KB 121.48 KB 121.79 KB NODE_DEV
react-reconciler.production.min.js 🔺+0.4% 🔺+0.4% 76.48 KB 76.8 KB 22.44 KB 22.54 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: 🔺+0.1%

Size changes (experimental)

Generated by 🚫 dangerJS against db9c751

@sizebot
Copy link

sizebot commented Mar 5, 2020

Details of bundled changes.

Comparing: fa03206...db9c751

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactDOM-profiling.js +0.3% +0.3% 406.37 KB 407.43 KB 74.08 KB 74.29 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% 0.0% 135.19 KB 135.19 KB 34.75 KB 34.75 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.2% 1.15 KB 1.15 KB 653 B 654 B NODE_PROD
react-dom-server.browser.production.min.js 0.0% 0.0% 20.05 KB 20.05 KB 7.42 KB 7.42 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 55.86 KB 55.86 KB 14.46 KB 14.46 KB NODE_DEV
react-dom.development.js 0.0% 0.0% 884.16 KB 884.16 KB 194.85 KB 194.85 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 9.99 KB 9.99 KB 3.36 KB 3.37 KB NODE_PROD
react-dom.production.min.js 0.0% -0.0% 116.01 KB 116.01 KB 37.17 KB 37.17 KB UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 119.54 KB 119.54 KB 38.33 KB 38.33 KB UMD_PROFILING
react-dom.development.js 0.0% 0.0% 841.41 KB 841.41 KB 192.42 KB 192.42 KB NODE_DEV
react-dom.production.min.js 0.0% 0.0% 116.09 KB 116.09 KB 36.5 KB 36.5 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% 0.0% 20.38 KB 20.38 KB 7.52 KB 7.53 KB NODE_PROD
react-dom.profiling.min.js 0.0% 0.0% 119.77 KB 119.77 KB 37.58 KB 37.58 KB NODE_PROFILING
ReactDOM-dev.js +0.2% +0.2% 939.77 KB 941.45 KB 209.49 KB 209.81 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.3% 🔺+0.3% 395.04 KB 396.1 KB 71.91 KB 72.11 KB FB_WWW_PROD
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 3.68 KB 3.68 KB 1.33 KB 1.33 KB NODE_DEV
ReactDOMTesting-dev.js +0.2% +0.2% 899.4 KB 901.08 KB 201 KB 201.32 KB FB_WWW_DEV
ReactDOMTesting-prod.js 🔺+0.3% 🔺+0.3% 382.29 KB 383.35 KB 69.64 KB 69.84 KB FB_WWW_PROD
react-dom-server.browser.development.js 0.0% 0.0% 128.27 KB 128.27 KB 34.33 KB 34.33 KB NODE_DEV
react-dom-test-utils.development.js 0.0% 0.0% 53.77 KB 53.77 KB 14 KB 14 KB UMD_DEV
ReactDOMTesting-profiling.js +0.3% +0.3% 382.29 KB 383.35 KB 69.64 KB 69.84 KB FB_WWW_PROFILING
react-dom-server.browser.production.min.js 0.0% 0.0% 19.97 KB 19.97 KB 7.38 KB 7.38 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 3.34 KB 3.34 KB 1.26 KB 1.26 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 10.94 KB 10.94 KB 4.16 KB 4.16 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1.17 KB 1.17 KB 689 B 691 B UMD_PROD
ReactDOMServer-dev.js 0.0% 0.0% 138.1 KB 138.1 KB 35.2 KB 35.2 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% -0.0% 49.55 KB 49.55 KB 13.51 KB 13.51 KB NODE_DEV
ReactDOMServer-prod.js 0.0% 0.0% 47.49 KB 47.49 KB 11.05 KB 11.05 KB FB_WWW_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 2.94 KB 2.94 KB 1.17 KB 1.17 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 10.79 KB 10.79 KB 4.09 KB 4.09 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 58.9 KB 58.9 KB 14.7 KB 14.7 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1013 B 1013 B 601 B 603 B NODE_PROD
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.26 KB 10.26 KB 3.48 KB 3.49 KB UMD_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactART-dev.js +0.3% +0.3% 567.69 KB 569.37 KB 118.97 KB 119.28 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.5% 🔺+0.5% 233.84 KB 234.9 KB 39.73 KB 39.94 KB FB_WWW_PROD
react-art.production.min.js 0.0% 0.0% 104.21 KB 104.21 KB 31.61 KB 31.61 KB UMD_PROD
react-art.production.min.js 0.0% 0.0% 69.25 KB 69.25 KB 20.79 KB 20.79 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: 0.0%

Size changes (stable)

Generated by 🚫 dangerJS against db9c751

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

Kind of subtle that _fn gets a different meaning and you need to remember to call initialise.

packages/react-reconciler/src/ReactFiberBeginWork.js Outdated Show resolved Hide resolved
@sebmarkbage
Copy link
Collaborator Author

The changing of _fn is same as Lazy. It changes. Even the functions have different call signatures so Flow should catch it. The thing that Flow doesn't have is "state classes" so there's no way to transition to a different type while staying in the type system so I have to briefly use "any" when changing the state. (It also has implications on threading.)

The initialization is unfortunate. There's a lot going on here. We can't throw in child fiber atm because that would bubble to the wrong parent potentially. We would also prevent siblings from warming up. I'm also not happy with the extra tuples created or the "if thennable" type check.

It took me like a month to get to this point and I'm still not happy with it. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants