perf: omit undefined props from LayoutRouter to reduce Flight payload#91601
Open
benfavre wants to merge 1 commit intovercel:canaryfrom
Open
perf: omit undefined props from LayoutRouter to reduce Flight payload#91601benfavre wants to merge 1 commit intovercel:canaryfrom
benfavre wants to merge 1 commit intovercel:canaryfrom
Conversation
…t payload When the RSC Flight payload serializes LayoutRouter elements, every undefined prop (error, errorStyles, errorScripts, templateStyles, templateScripts, notFound, forbidden, unauthorized) is emitted as a "$undefined" reference. For a route with 10+ layouts this produces ~100 redundant "$undefined" literals adding ~1.4KB to the response and ~100 extra serialization round-trips. Build the LayoutRouter props object conditionally so that only non-undefined values are included. The OuterLayoutRouter component already types all these props as `T | undefined` and uses them directly (no `'prop' in props` checks), so omitting them entirely is semantically equivalent to passing `undefined`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collaborator
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
1 similar comment
Collaborator
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
Contributor
Author
Performance ImpactProfiling setup: Node.js v25.7.0, analysis of RSC Flight payload for Before:
After:
Test Verification
|
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.
Summary
createComponentTreeInternalso that undefined values (error,errorStyles,errorScripts,templateStyles,templateScripts,notFound,forbidden,unauthorized) are omitted from the element rather than passed explicitly asundefined$undefinedreferences per response for deeply nested routes (10+ layouts), saving ~1.4KB of Flight payload per requestT | undefinedwith no'prop' in propschecks, so omitting them is semantically identical to passingundefinedWhy
The RSC Flight protocol serializes every prop value, including
undefined(as the$undefinedsentinel). For a typical route with 10+ layout segments and parallel routes, each LayoutRouter element carries 8 undefined props. That's ~100$undefinedreferences across the response — pure overhead in both payload size and serialization/deserialization work.What changed
packages/next/src/server/app-render/create-component-tree.tsx: Instead of always passing all props tocreateElement(LayoutRouter, {...}), we now build a props object that only includes truthy values, then pass that object tocreateElement.Test plan
undefinedprops and absent props are equivalent for the consumer component)$undefinedentries for LayoutRouter elements🤖 Generated with Claude Code