Skip to content

refactor: migrate jumpToState to Astro.licals to prevent build-time state leakage#1271

Open
riya-saharan wants to merge 1 commit intoprocessing:mainfrom
riya-saharan:main
Open

refactor: migrate jumpToState to Astro.licals to prevent build-time state leakage#1271
riya-saharan wants to merge 1 commit intoprocessing:mainfrom
riya-saharan:main

Conversation

@riya-saharan
Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant