[Flight] Standardize ClientReferenceMetadata tuple type#36197
Draft
unstubbable wants to merge 1 commit intofacebook:mainfrom
Draft
[Flight] Standardize ClientReferenceMetadata tuple type#36197unstubbable wants to merge 1 commit intofacebook:mainfrom
ClientReferenceMetadata tuple type#36197unstubbable wants to merge 1 commit intofacebook:mainfrom
Conversation
Previously, `ClientReferenceMetadata` was declared as an opaque type in
the Flight server config (`ReactFlightServerConfigBundlerCustom.js`),
with each bundler defining its own tuple shape. Webpack, Turbopack, and
Unbundled used `[id, chunks, name, async?]` while Parcel used `[id,
name, bundles, importMap?]`, placing the chunks array at different
indices. This made it impossible for `ReactFlightServer.js` to access
the chunks array without bundler-specific accessor functions.
This change standardizes all bundlers on a common shape where `id` is at
index 0, `name` is at index 1, and `chunks` is at index 2. A bundler-
specific extra like the async flag or Parcel's `importMap` can go at
index 3. The `ClientReferenceMetadata` type is changed from an opaque
type to a concrete union type, so `ReactFlightServer.js` can now
directly access `metadata[2]` to get the chunks array with proper Flow
typing.
This only affects the internal wire format tuple, not the
`ClientManifest` that frameworks pass into Flight. The manifest entry
shape (`{id, chunks, name, async?}`) remains unchanged.
The motivation is to enable deduplicating individual chunk URLs across
client references in the RSC stream. With a known, non-opaque type,
`emitImportChunk` can extract, deduplicate, and replace chunk entries
without needing bundler-specific callback functions or accessor methods.
60b41f0 to
af24e98
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously,
ClientReferenceMetadatawas declared as an opaque type in the Flight server config (ReactFlightServerConfigBundlerCustom.js), with each bundler defining its own tuple shape. Webpack, Turbopack, and Unbundled used[id, chunks, name, async?]while Parcel used[id, name, bundles, importMap?], placing the chunks array at different indices. This made it impossible forReactFlightServer.jsto access the chunks array without bundler-specific accessor functions.This change standardizes all bundlers on a common shape where
idis at index 0,nameis at index 1, andchunksis at index 2. A bundler- specific extra like the async flag or Parcel'simportMapcan go at index 3. TheClientReferenceMetadatatype is changed from an opaque type to a concrete union type, soReactFlightServer.jscan now directly accessmetadata[2]to get the chunks array with proper Flow typing.This only affects the internal wire format tuple, not the
ClientManifestthat frameworks pass into Flight. The manifest entry shape ({id, chunks, name, async?}) remains unchanged.The motivation is to enable deduplicating individual chunk URLs across client references in the RSC stream. With a known, non-opaque type,
emitImportChunkcan extract, deduplicate, and replace chunk entries without needing bundler-specific callback functions or accessor methods.