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

[Flight] Allow values to be encoded by "reference" to a value rather than the value itself #20136

Merged
merged 1 commit into from
Oct 30, 2020

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Oct 30, 2020

These references are currently transformed into React.lazy values. We can use these in React positions like element type or node position.

This could be expanded to a more general concept like Suspensey Promises, asset references or JSResourceReferences.

For now it's only used in React Element type position.

The purpose of these is to let you suspend deeper in the tree.

"$1234" in the JSON gets replaced with the actual value of row/chunk number 1234.

"@1234" in the JSON gets replaced with a React.lazy object that when read either suspends or returns the actual value of row/chunk number 1234.

…value itself

These references are currently transformed into React.lazy values. We can use these in
React positions like element type or node position.

This could be expanded to a more general concept like Suspensey Promises, asset references or JSResourceReferences.

For now it's only used in React Element type position.

The purpose of these is to let you suspend deeper in the tree.
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Oct 30, 2020
@codesandbox-ci
Copy link

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 e87f38c:

Sandbox Source
React Configuration

@sizebot
Copy link

sizebot commented Oct 30, 2020

Details of bundled changes.

Comparing: 39eb6d1...e87f38c

react-transport-dom-relay

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactFlightDOMRelayServer-dev.js +2.0% +2.3% 25.04 KB 25.54 KB 6.45 KB 6.6 KB FB_WWW_DEV
ReactFlightDOMRelayServer-prod.js 🔺+0.7% 🔺+0.7% 14.91 KB 15.01 KB 3.88 KB 3.91 KB FB_WWW_PROD
ReactFlightDOMRelayClient-dev.js +4.5% +3.2% 11.67 KB 12.19 KB 3.46 KB 3.56 KB FB_WWW_DEV
ReactFlightDOMRelayClient-prod.js 🔺+4.4% 🔺+1.5% 5.33 KB 5.57 KB 1.6 KB 1.63 KB FB_WWW_PROD

react-transport-dom-webpack

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-transport-dom-webpack-server-runtime.development.js 0.0% -0.1% 2.99 KB 2.99 KB 1.07 KB 1.07 KB NODE_DEV
react-transport-dom-webpack-server-runtime.production.min.js 0.0% -0.3% 513 B 513 B 351 B 350 B NODE_PROD
react-transport-dom-webpack.development.js +3.4% +2.2% 18.19 KB 18.81 KB 5 KB 5.11 KB UMD_DEV
react-transport-dom-webpack.production.min.js 🔺+3.7% 🔺+1.9% 4.01 KB 4.16 KB 1.81 KB 1.84 KB UMD_PROD
react-transport-dom-webpack.development.js +3.4% +2.3% 16.97 KB 17.55 KB 4.88 KB 4.99 KB NODE_DEV
react-transport-dom-webpack.production.min.js 🔺+4.0% 🔺+1.6% 3.81 KB 3.96 KB 1.71 KB 1.74 KB NODE_PROD
react-transport-dom-webpack-server.node.development.js +2.0% +2.2% 24.82 KB 25.32 KB 6.73 KB 6.88 KB NODE_DEV
react-transport-dom-webpack-server.browser.development.js +2.1% +2.3% 25.45 KB 25.98 KB 6.6 KB 6.75 KB UMD_DEV
react-transport-dom-webpack-server.node.production.min.js 🔺+0.6% 🔺+0.5% 6.44 KB 6.48 KB 2.66 KB 2.67 KB NODE_PROD
react-transport-dom-webpack-server.browser.production.min.js 🔺+0.6% 🔺+0.5% 6.47 KB 6.5 KB 2.71 KB 2.73 KB UMD_PROD
react-transport-dom-webpack-server.browser.development.js +2.1% +2.4% 23.88 KB 24.38 KB 6.47 KB 6.62 KB NODE_DEV
react-transport-dom-webpack-plugin.js 0.0% -0.3% 437 B 437 B 298 B 297 B NODE_ES2015
react-transport-dom-webpack-server.browser.production.min.js 🔺+0.6% 🔺+0.5% 6.26 KB 6.29 KB 2.64 KB 2.65 KB NODE_PROD

react-client

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-client-flight.development.js +3.9% +2.5% 14.95 KB 15.53 KB 4.37 KB 4.48 KB NODE_DEV
react-client-flight.production.min.js 🔺+4.4% 🔺+1.6% 3.4 KB 3.55 KB 1.54 KB 1.57 KB NODE_PROD

react-server

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-server-flight-server-runtime.development.js 0.0% -0.2% 2.98 KB 2.98 KB 1.06 KB 1.06 KB NODE_DEV
react-server-flight-server-runtime.production.min.js 0.0% -0.3% 505 B 505 B 339 B 338 B NODE_PROD
react-server-flight.development.js +2.1% +2.4% 24.31 KB 24.82 KB 6.59 KB 6.75 KB NODE_DEV
react-server-flight.production.min.js 🔺+0.6% 🔺+0.6% 6.51 KB 6.55 KB 2.7 KB 2.72 KB NODE_PROD
react-server.development.js 0.0% -0.1% 5.45 KB 5.45 KB 1.73 KB 1.73 KB NODE_DEV
react-server.production.min.js 0.0% -0.2% 1.16 KB 1.16 KB 650 B 649 B NODE_PROD

Size changes (experimental)

Generated by 🚫 dangerJS against e87f38c

@sizebot
Copy link

sizebot commented Oct 30, 2020

Details of bundled changes.

Comparing: 39eb6d1...e87f38c

react-transport-dom-relay

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactFlightDOMRelayServer-dev.js +2.0% +2.3% 25.04 KB 25.54 KB 6.45 KB 6.6 KB FB_WWW_DEV
ReactFlightDOMRelayServer-prod.js 🔺+0.7% 🔺+0.7% 14.91 KB 15.01 KB 3.88 KB 3.91 KB FB_WWW_PROD
ReactFlightDOMRelayClient-dev.js +4.5% +3.2% 11.67 KB 12.19 KB 3.46 KB 3.56 KB FB_WWW_DEV
ReactFlightDOMRelayClient-prod.js 🔺+4.4% 🔺+1.5% 5.33 KB 5.57 KB 1.6 KB 1.63 KB FB_WWW_PROD

react-transport-dom-webpack

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-transport-dom-webpack-server-runtime.development.js 0.0% -0.1% 2.98 KB 2.98 KB 1.07 KB 1.07 KB NODE_DEV
react-transport-dom-webpack-server-runtime.production.min.js 0.0% -0.3% 500 B 500 B 341 B 340 B NODE_PROD
react-transport-dom-webpack.development.js +3.4% +2.3% 18.18 KB 18.8 KB 4.99 KB 5.1 KB UMD_DEV
react-transport-dom-webpack.production.min.js 🔺+3.8% 🔺+1.9% 4 KB 4.15 KB 1.8 KB 1.83 KB UMD_PROD
react-transport-dom-webpack.development.js +3.4% +2.2% 16.96 KB 17.54 KB 4.87 KB 4.98 KB NODE_DEV
react-transport-dom-webpack.production.min.js 🔺+4.0% 🔺+1.7% 3.8 KB 3.95 KB 1.7 KB 1.73 KB NODE_PROD
react-transport-dom-webpack-server.node.development.js +2.0% +2.2% 24.8 KB 25.31 KB 6.72 KB 6.88 KB NODE_DEV
react-transport-dom-webpack-server.browser.development.js +2.1% +2.3% 25.44 KB 25.96 KB 6.59 KB 6.75 KB UMD_DEV
react-transport-dom-webpack-server.node.production.min.js 🔺+0.6% 🔺+0.5% 6.43 KB 6.47 KB 2.65 KB 2.67 KB NODE_PROD
react-transport-dom-webpack-server.browser.production.min.js 🔺+0.6% 🔺+0.6% 6.45 KB 6.49 KB 2.7 KB 2.72 KB UMD_PROD
react-transport-dom-webpack-server.browser.development.js +2.1% +2.4% 23.86 KB 24.37 KB 6.46 KB 6.61 KB NODE_DEV
react-transport-dom-webpack-server.browser.production.min.js 🔺+0.6% 🔺+0.5% 6.25 KB 6.28 KB 2.63 KB 2.64 KB NODE_PROD

react-client

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-client-flight.development.js +3.9% +2.5% 14.93 KB 15.51 KB 4.37 KB 4.47 KB NODE_DEV
react-client-flight.production.min.js 🔺+4.4% 🔺+1.7% 3.38 KB 3.53 KB 1.54 KB 1.56 KB NODE_PROD

react-server

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-server-flight-server-runtime.development.js 0.0% -0.1% 2.97 KB 2.97 KB 1.06 KB 1.05 KB NODE_DEV
react-server-flight-server-runtime.production.min.js 0.0% -0.6% 492 B 492 B 331 B 329 B NODE_PROD
react-server-flight.development.js +2.1% +2.4% 24.3 KB 24.8 KB 6.58 KB 6.74 KB NODE_DEV
react-server-flight.production.min.js 🔺+0.6% 🔺+0.6% 6.5 KB 6.53 KB 2.7 KB 2.71 KB NODE_PROD
react-server.development.js 0.0% -0.1% 5.43 KB 5.43 KB 1.72 KB 1.72 KB NODE_DEV
react-server.production.min.js 0.0% -0.2% 1.15 KB 1.15 KB 642 B 641 B NODE_PROD

Size changes (stable)

Generated by 🚫 dangerJS against e87f38c

@@ -479,12 +483,20 @@ export function resolveModelToJSON(
request.pendingChunks++;
const moduleId = request.nextChunkId++;
emitModuleChunk(request, moduleId, moduleMetaData);
return serializeIDRef(moduleId);
if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does 1 mean here? Is this because it's a tuple?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yea

@sebmarkbage sebmarkbage merged commit 930ce7c into facebook:master Oct 30, 2020
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Nov 9, 2020
Summary:
Base sync before adding Flight files.

This sync includes the following changes:
- **[454c2211c](facebook/react@454c2211c )**: Refactor SchedulerHostConfigs ([#20025](facebook/react#20025)) //<Ricky>//
- **[56e9feead](facebook/react@56e9feead )**: Remove Blocks ([#20138](facebook/react#20138)) //<Sebastian Markbåge>//
- **[3fbd47b86](facebook/react@3fbd47b86 )**: Serialize pending server components by reference (lazy component) ([#20137](facebook/react#20137)) //<Sebastian Markbåge>//
- **[930ce7c15](facebook/react@930ce7c15 )**: Allow values to be encoded by "reference" to a value rather than the value itself ([#20136](facebook/react#20136)) //<Sebastian Markbåge>//
- **[39eb6d176](facebook/react@39eb6d176 )**: Rename ([#20134](facebook/react#20134)) //<Sebastian Markbåge>//
- **[ffd842335](facebook/react@ffd842335 )**: [Flight] Add support for Module References in transport protocol ([#20121](facebook/react#20121)) //<Sebastian Markbåge>//
- **[343d7a4a7](facebook/react@343d7a4a7 )**: Fast Refresh: Don't block DevTools commit hook ([#20129](facebook/react#20129)) //<Brian Vaughn>//
- **[779a472b0](facebook/react@779a472b0 )**: Prevent inlining into recursive commit functions ([#20105](facebook/react#20105)) //<Andrew Clark>//
- **[25b18d31c](facebook/react@25b18d31c )**: Traverse commit phase effects iteratively ([#20094](facebook/react#20094)) //<Andrew Clark>//

Changelog:
[General][Changed] - React Native sync for revisions 4e5d7fa...454c221

Reviewed By: rickhanlonii

Differential Revision: D24698701

fbshipit-source-id: dfaf692b1051150355dece1657764a484b7ae603
koto pushed a commit to koto/react that referenced this pull request Jun 15, 2021
…value itself (facebook#20136)

These references are currently transformed into React.lazy values. We can use these in
React positions like element type or node position.

This could be expanded to a more general concept like Suspensey Promises, asset references or JSResourceReferences.

For now it's only used in React Element type position.

The purpose of these is to let you suspend deeper in the tree.
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