fix: add manualChunks to resolve TDZ error in production build#90
Open
epuerta9 wants to merge 1 commit into
Open
fix: add manualChunks to resolve TDZ error in production build#90epuerta9 wants to merge 1 commit into
epuerta9 wants to merge 1 commit into
Conversation
Fixes #82 The production UI bundle was experiencing a Temporal Dead Zone (TDZ) error ("Cannot access 'Se' before initialization") due to circular dependencies being bundled into a single large chunk. This fix adds manualChunks configuration to split the bundle: - react-vendor: React core libraries (react, react-dom, react-router-dom) - ui-vendor: UI component libraries (radix-ui, lucide-react, recharts) - utils: Utility libraries (date-fns, clsx, tailwind-merge, zod) Splitting the bundle ensures proper module initialization order and prevents TDZ violations caused by circular dependencies.
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
Fixes #82 - UI JavaScript Error: ReferenceError on /agents/default page
Problem Analysis
The production UI bundle was throwing a Temporal Dead Zone (TDZ) error:
This error occurred because:
Root Cause
In JavaScript, variables declared with
letandconstexist in a "Temporal Dead Zone" from the start of their scope until they are initialized. When Rollup/Vite bundles code with circular dependencies into a single chunk, the module evaluation order can cause some variables to be accessed before their initialization, triggering TDZ errors.Solution
Added
manualChunksconfiguration toui/vite.config.tsto split the bundle into separate chunks:react-vendorui-vendorutilsThis ensures:
Files Modified
ui/vite.config.ts- AddedmanualChunksconfigurationTesting Notes
make build-uiorcd ui && npm run buildinternal/ui/static/assets/STN_DEV_MODE=true stn serve --localAdditional Benefits