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

[Selective Hydration] ReactDOM.unstable_scheduleHydration(domNode) #17004

Merged
merged 1 commit into from
Oct 3, 2019

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Oct 3, 2019

Adds an API to explicitly prioritize hydrating the path to a particular DOM node without relying on events to do it.

The API uses the current scheduler priority to schedule it. For the same priority, the last one wins. This allows a similar effect as continuous events. This is useful for example to hydrate based on scroll position, or prioritize components that will upgrade to client-rendered-only content.

I considered having an API that explicitly overrides the current target(s). However that makes it difficult to coordinate across components in an app.

This just hydrates one target at a time but if it is blocked on I/O we could consider increasing priority of later targets too.

@sizebot
Copy link

sizebot commented Oct 3, 2019

ReactDOM: size: 0.0%, gzip: -0.0%

Details of bundled changes.

Comparing: 26ba38a...a1cb22c

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js +0.5% +0.3% 121.34 KB 121.9 KB 38.22 KB 38.34 KB NODE_PROFILING
ReactDOM-dev.js +0.3% +0.3% 976.08 KB 979.37 KB 216.51 KB 217.24 KB FB_WWW_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 19.86 KB 19.86 KB 7.38 KB 7.37 KB UMD_PROD
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.78 KB 3.78 KB 1.53 KB 1.53 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 11.19 KB 11.19 KB 4.16 KB 4.16 KB UMD_PROD
react-dom-test-utils.production.min.js 0.0% -0.0% 10.96 KB 10.96 KB 4.09 KB 4.09 KB NODE_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.2% 1.04 KB 1.04 KB 633 B 632 B NODE_PROD
react-dom.development.js +0.3% +0.3% 951.63 KB 954.9 KB 215.37 KB 216.05 KB UMD_DEV
react-dom.production.min.js 🔺+0.5% 🔺+0.2% 117.59 KB 118.13 KB 37.89 KB 37.98 KB UMD_PROD
react-dom.profiling.min.js +0.4% +0.3% 121.11 KB 121.65 KB 38.91 KB 39.02 KB UMD_PROFILING
react-dom.development.js +0.3% +0.3% 945.68 KB 948.97 KB 213.8 KB 214.48 KB NODE_DEV
react-dom.production.min.js 🔺+0.5% 🔺+0.3% 117.7 KB 118.26 KB 37.21 KB 37.32 KB NODE_PROD
ReactDOM-prod.js 🔺+0.5% 🔺+0.6% 398.69 KB 400.87 KB 72.73 KB 73.14 KB FB_WWW_PROD
ReactDOM-profiling.js +0.5% +0.5% 399.51 KB 401.68 KB 73.26 KB 73.65 KB FB_WWW_PROFILING
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.75 KB 10.75 KB 3.67 KB 3.67 KB UMD_PROD
ReactDOMServer-prod.js 0.0% -0.0% 48.24 KB 48.24 KB 11.04 KB 11.04 KB FB_WWW_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.2 KB 60.2 KB 15.71 KB 15.71 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.49 KB 10.49 KB 3.57 KB 3.57 KB NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.1% 0.0% 601.55 KB 602.03 KB 127.46 KB 127.51 KB NODE_DEV
react-reconciler.production.min.js 🔺+0.1% 🔺+0.1% 71.79 KB 71.9 KB 21.25 KB 21.28 KB NODE_PROD
react-reconciler-reflection.development.js 0.0% -0.0% 19.76 KB 19.76 KB 6.39 KB 6.39 KB NODE_DEV
react-reconciler-reflection.production.min.js 0.0% -0.1% 2.88 KB 2.88 KB 1.25 KB 1.25 KB NODE_PROD
react-reconciler-persistent.development.js +0.1% 0.0% 598.73 KB 599.2 KB 126.27 KB 126.32 KB NODE_DEV
react-reconciler-persistent.production.min.js 🔺+0.1% 🔺+0.1% 71.8 KB 71.91 KB 21.26 KB 21.28 KB NODE_PROD

Generated by 🚫 dangerJS against a1cb22c

Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

LGTM

let spanB = container.getElementsByTagName('span')[1];
let spanC = container.getElementsByTagName('span')[2];

// A and D will be suspended. We'll click on D which should take
Copy link
Contributor

Choose a reason for hiding this comment

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

nit Copy-pasta comment is confusing. There's no D and we don't click anything.

@@ -841,6 +845,12 @@ const ReactDOM: Object = {
unstable_createSyncRoot: createSyncRoot,
unstable_flushControlled: flushControlled,

unstable_scheduleHydration(target: Node) {
if (target) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason behind silently nooping if we're passed an invalid target?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mostly because it's pretty common to pass in getElementById and probably not worth taking down the site since this feature has no important semantic meaning other than perf. It should probably be a warning at some point though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, seems like we should at least warn since the overall scheduling behavior is a bit opaque to begin with. (Might be easy to overlook an error like a misspelled id.)

Adds an API to explicitly prioritize hydrating the path to a particular
DOM node without relying on events to do it.

The API uses the current scheduler priority to schedule it. For the same
priority, the last one wins. This allows a similar effect as continuous
events. This is useful for example to hydrate based on scroll position.

I considered having an API that explicitly overrides the current target(s).
However that makes it difficult to coordinate across components in an app.

This just hydrates on target at a time but if it is blocked on I/O we could
consider increasing priority of later targets too.
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