Skip to content

fix: resolve Vitest TDZ on NiceNavigationItemRef initialization#5

Open
gabrielroberge wants to merge 1 commit into
masterfrom
fix/vitest
Open

fix: resolve Vitest TDZ on NiceNavigationItemRef initialization#5
gabrielroberge wants to merge 1 commit into
masterfrom
fix/vitest

Conversation

@gabrielroberge

Copy link
Copy Markdown
Contributor

Summary

Fixes a ReferenceError: Cannot access 'NiceNavigationItemRef' before initialization occurring under Vitest when a consumer project loads the package TypeScript sources through sourcemaps. ng serve / ng build were not impacted.

Problem

Two combined causes in the navigation module graph:

1. TDZ in NiceNavigationItemsRenderer

Signal field initializers access NiceNavigationItemRef during class evaluation:

contentChildren(NiceNavigationItemRef, )
inject(NiceNavigationItemRef, )

Angular metadata already used forwardRef, but the compiled field initializers did not.

2. Runtime import cycle

navigation-items.ts → navigation-item-ref.ts → navigation.ts → navigation-items.ts

Changes

navigation-items.ts

  • Added forwardRef to contentChildren and inject.

navigation-item-ref.ts

  • Replaced the NiceNavigation runtime import with NiceNavigationItemsRenderer.
  • Added forwardRef to inject to break the runtime cycle down to 3 files.

Impact

  • No public API changes.
  • No regression on ng serve / ng build.

Note:

This bug is not reproducible through ng test inside the library itself because @angular/build:unit-test bundles all sources into a single Vite chunk, masking the ESM initialization-order issue.

@gabrielroberge gabrielroberge changed the title chore: add .npmrc for package management configuration fix: resolve Vitest TDZ on NiceNavigationItemRef initialization Jun 13, 2026
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