Skip to content

fix: resolve TDZ error in defineI18nLabels by breaking circular dependency#183

Open
IzumiSy wants to merge 3 commits intomainfrom
fix/definei18nlabels-tdz-error
Open

fix: resolve TDZ error in defineI18nLabels by breaking circular dependency#183
IzumiSy wants to merge 3 commits intomainfrom
fix/definei18nlabels-tdz-error

Conversation

@IzumiSy
Copy link
Copy Markdown
Contributor

@IzumiSy IzumiSy commented Apr 17, 2026

Summary

Fixes a runtime TDZ (Temporal Dead Zone) error — "Cannot access before initialization" — that occurred when calling defineI18nLabels at module top-level in production builds (vite build). The issue did not occur in development mode.

Root Cause

A circular module dependency was introduced in v0.34.0:

hooks/i18n.ts
  → appshell-context.tsx   (imports useAppShellConfig)
    → default-error-boundary.tsx   (imports DefaultErrorBoundary)
      → i18n-labels.ts   (imports useT)
        → hooks/i18n.ts   ← circular

When Rollup linearizes this cycle for the production bundle, defineI18nLabels (a const declaration in hooks/i18n.ts) can be accessed before it is initialized, causing a TDZ error.

Fix

Remove the DefaultErrorBoundary import from appshell-context.tsx, breaking the cycle. The default value is now applied in appshell.tsx — which has no path back into hooks/i18n.ts — via props.errorBoundary ?? <DefaultErrorBoundary />.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 17, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@tailor-platform/app-shell@183
npm i https://pkg.pr.new/@tailor-platform/app-shell-vite-plugin@183

commit: 26e13f0

@IzumiSy
Copy link
Copy Markdown
Contributor Author

IzumiSy commented Apr 17, 2026

/review

@IzumiSy
Copy link
Copy Markdown
Contributor Author

IzumiSy commented Apr 17, 2026

No issue reported by AI review

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