Skip to content

Fix embroiderVite-basics: guard COMPUTED_GETTERS.has() with DEV check#21118

Merged
NullVoxPopuli merged 2 commits intonvp/no-more-macrosfrom
copilot/sub-pr-21115
Feb 26, 2026
Merged

Fix embroiderVite-basics: guard COMPUTED_GETTERS.has() with DEV check#21118
NullVoxPopuli merged 2 commits intonvp/no-more-macrosfrom
copilot/sub-pr-21115

Conversation

Copy link
Contributor

Copilot AI commented Feb 26, 2026

When building with vite build --mode test, Vite sets import.meta.env.DEV to false, so COMPUTED_GETTERS (a WeakSet) is never initialized — but COMPUTED_GETTERS.has() was called unconditionally as an argument to assert(). Since assert is a no-op in production (not tree-shaken away entirely), its arguments are still evaluated, causing a crash at startup.

Change

  • packages/@ember/-internals/metal/lib/decorator.ts: Guard the .has() call in makeComputedDecorator's assert() with import.meta.env?.DEV && so it short-circuits before touching the uninitialized WeakSet in non-dev builds:
// Before
!COMPUTED_GETTERS.has(propertyDesc.get)

// After — short-circuits when DEV is false, COMPUTED_GETTERS stays undefined safely
!(import.meta.env?.DEV && COMPUTED_GETTERS.has(propertyDesc.get))

The assertion still works correctly in dev mode; in production/test builds the condition simply evaluates to true (no-op), matching the intended behavior since assert is already a no-op there.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

When building with `vite build --mode test`, import.meta.env.DEV is false,
so COMPUTED_GETTERS (a WeakSet) is never initialized. The assert() call in
makeComputedDecorator was unconditionally evaluating COMPUTED_GETTERS.has(),
causing TypeError: Cannot read properties of undefined (reading 'has').

Guard the .has() call with `import.meta.env?.DEV &&` so it short-circuits
before accessing the undefined WeakSet in production/test builds.

Co-authored-by: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove macros in favor of import.meta.env?.DEV Fix embroiderVite-basics: guard COMPUTED_GETTERS.has() with DEV check Feb 26, 2026
@NullVoxPopuli NullVoxPopuli marked this pull request as ready for review February 26, 2026 02:30
@NullVoxPopuli NullVoxPopuli merged commit eca6385 into nvp/no-more-macros Feb 26, 2026
@NullVoxPopuli NullVoxPopuli deleted the copilot/sub-pr-21115 branch February 26, 2026 02:30
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.

2 participants