refactor: migrate jumpToState to Astro.licals to prevent build-time state leakage#1271
Open
riya-saharan wants to merge 1 commit intoprocessing:mainfrom
Open
refactor: migrate jumpToState to Astro.licals to prevent build-time state leakage#1271riya-saharan wants to merge 1 commit intoprocessing:mainfrom
riya-saharan wants to merge 1 commit intoprocessing:mainfrom
Conversation
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.
This PR addresses the issue of state leakage across different locales during parallel static builds.
The Problem:
Previously, the jumpToState (used for the "Jump To" sidebar) was managed via a global singleton in src/globals/state.ts. During high-concurrency builds, pages from different locales (e.g., Korean and Chinese) would overwrite this global variable, leading to incorrect translations appearing on the wrong pages.
The Solution:
I have migrated the state management to Astro.locals, which provides an isolated data store for every unique request/page build.
Key Changes:
State Isolation: Moved jumpToState into App.Locals via env.d.ts.
Component Updates: Refactored Nav.astro, NavPanels.tsx, and Settings.tsx to consume state from the request context.
Thread-Safety: Removed the global variable and setter from state.ts.
Lifecycle Management: Updated all layouts and localized page entry points to explicitly set or reset their own jumpToState within the Astro.locals scope.
Verification:
Successfully passed npm run build with 0 errors. Verified language isolation in a local preview environment across multiple localized routes.