-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move client build ID to a global variable (#72592)
When performing RSC requests, if the incoming data has a different build ID than the client, we perform an MPA navigation/refresh to load the updated build and ensure that the client and server in sync. Currently we store the build ID in the router state, but becauase it's always in lockstep with the app instance, it's not actually stateful. We can store it in a global. The ID gets assigned as a side-effect during app initialization. It should never change after being set the first time. In practice, because setAppBuildId is called before hydration starts, it will always get assigned to the actual build ID before it's ever needed by a navigation. (If for some reasons it didn't, due to a bug or race condition, then on navigation the build comparision would fail and trigger an MPA navigation.) The logical flow of how the global is assigned is more convoluted than it should be because we currently decode the Flight stream inside the React render phase (via a hook), because that's required to propagate resource hints correctly. Conceptually it would make more sense to decode the stream before starting hydration and pass the decoded data to the root component as props; this would also allow us to block hydration until the id is set. But we'll need to address the hints problem first. As a follow up, we should probably do the same thing for the App Router reducer, which is already a global store in practice but is referenced and passed everywhere as if it were owned by the React tree.
- Loading branch information
Showing
18 changed files
with
35 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// This gets assigned as a side-effect during app initialization. Because it | ||
// represents the build used to create the JS bundle, it should never change | ||
// after being set, so we store it in a global variable. | ||
// | ||
// When performing RSC requests, if the incoming data has a different build ID, | ||
// we perform an MPA navigation/refresh to load the updated build and ensure | ||
// that the client and server in sync. | ||
|
||
// Starts as an empty string. In practice, because setAppBuildId is called | ||
// during initialization before hydration starts, this will always get | ||
// reassigned to the actual build ID before it's ever needed by a navigation. | ||
// If for some reasons it didn't, due to a bug or race condition, then on | ||
// navigation the build comparision would fail and trigger an MPA navigation. | ||
let globalBuildId: string = '' | ||
|
||
export function setAppBuildId(buildId: string) { | ||
globalBuildId = buildId | ||
} | ||
|
||
export function getAppBuildId(): string { | ||
return globalBuildId | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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