Skip to content

[BUGFIX] modifier destruction order varies between dev and prod - #21639

Merged
ef4 merged 2 commits into
mainfrom
fix/modifier-destruction-order
Sep 30, 2026
Merged

ef4 merged 2 commits into
mainfrom
fix/modifier-destruction-order

Conversation

@ef4

@ef4 ef4 commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

The order of modifier destructors varies between dev and prod builds.

This fix ensures that dev builds use the same destruction order as production builds.

The tests record destruction order with the debug render tree enabled (the default in tests) and with it disabled and ensure that the order must be the same.

The issue was identified as part of the template-language-spec experimental branch.

ef4 and others added 2 commits September 30, 2026 12:42
…der tree

Production builds destroy a modifier after the modifiers inside its element,
because the modifier is associated with its parent destroyable when the
element closes. With the debug render tree on (the default in development),
addModifier also associates the modifier's state when it is created, so
modifiers are destroyed in creation order instead.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…tree

With the debug render tree on, addModifier associated each modifier's state
with its parent destroyable as soon as the modifier was created, so
modifiers were destroyed in creation order (an element's modifier before
the modifiers inside it). Without it, which is how production builds run,
a modifier is associated when its element closes, so it is destroyed after
the modifiers inside its element.

The debug-render-tree association now happens when the element closes,
next to the manager's own destroyable, so both builds use the production
order.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ef4 ef4 added the bug label Sep 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📊 Size report

Tarball size — 1.2 MB → 1.2 MB

dist/dev   0.03%↑

File Before (Size / Brotli) After (Size / Brotli)
./packages/shared-chunks/arguments-{hash}.js 61.5 kB / 12 kB 1%↑62.1 kB / 1%↑12.2 kB
./packages/shared-chunks/template-{hash}.js 1.1 kB / 401 B -54%↓491 B / -49.4%↓203 B
Total (Includes all files) 2.1 MB / 508.6 kB 0.03%↑2.1 MB / 0.03%↑508.8 kB

dist/prod   0.03%↑

File Before (Size / Brotli) After (Size / Brotli)
./packages/shared-chunks/arguments-{hash}.js 57.9 kB / 11.3 kB 1%↑58.6 kB / 1%↑11.5 kB
Total (Includes all files) 1.9 MB / 465.4 kB 0.03%↑1.9 MB / 0.05%↑465.6 kB

smoke-tests/v2-app-template/dist   0.03%↑

File Before (Size / Brotli) After (Size / Brotli)
Total (Includes all files) 352.7 kB / 96.2 kB 0.03%↑352.8 kB / 0.1%↑96.3 kB

smoke-tests/v2-app-hello-world-template/dist   0.07%↑

File Before (Size / Brotli) After (Size / Brotli)
Total (Includes all files) 135.7 kB / 37.9 kB 0.07%↑135.8 kB / 0.06%↑37.9 kB

🤖 This report was automatically generated by wyvox/pkg-size

vm.env.scheduleInstallModifier(modifier);
const d = modifier.manager.getDestroyable(modifier.state);
const { state } = modifier;
const d = modifier.manager.getDestroyable(state);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good find


// For tearing down the debugRenderTree entry that addModifier created. This happens here,
// with the modifier's own destroyable, so that modifiers are destroyed in the same order
// with or without the debug render tree.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you testing with the debug render tree disabled?

I'd very much like a build flag (not runtime flag) to disable this haha

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not especially, just the one test in this PR that explicitly forces it to off for the duration of the test.

@ef4
ef4 merged commit 153364b into main Sep 30, 2026
70 checks passed
@ef4
ef4 deleted the fix/modifier-destruction-order branch September 30, 2026 17:56
ef4 added a commit that referenced this pull request Sep 30, 2026
…difier order fix landed (#21639)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ef4 added a commit that referenced this pull request Oct 1, 2026
- Shift 68 citations into the files the merge changed, using the new
  tools/remap-citations.py (hunk offsets from git diff).
- Rewrite the notes that said this checkout predated a fix: §01-1.6.3,
  §03-4.6, §03-7.3, §05-11.1, §05-11.3, §06-10.3, §07-3.1.5 and §08-2.20
  now cite the fixed code and the tests that landed with it.
- STATUS: new merge base, how to keep citations current, T13 row.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants