Skip to content

[BUGFIX lts] Destroy dynamic modifiers that were set after the initial render - #21591

Merged
NullVoxPopuli merged 2 commits into
emberjs:mainfrom
NullVoxPopuli-ai-agent:nvp/fix-dynamic-modifier-teardown
Sep 4, 2026
Merged

NullVoxPopuli merged 2 commits into
emberjs:mainfrom
NullVoxPopuli-ai-agent:nvp/fix-dynamic-modifier-teardown

Conversation

@NullVoxPopuli-ai-agent

@NullVoxPopuli-ai-agent NullVoxPopuli-ai-agent commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Dynamic modifiers that become defined after the first render never run their destructor. This leaks whatever the modifier set up, for example the @floating-ui/dom observers behind universal-ember/ember-primitives#805.

Mechanism, in packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts:

  1. {{this.mod}} renders with this.mod as undefined. No instance is created, and an UpdateDynamicModifierOpcode is pushed with vm.updateWith.
  2. this.mod becomes a modifier. UpdateDynamicModifierOpcode.evaluate creates the instance and calls associateDestroyableChild(this, destroyable).
  3. The opcode itself was never registered as a destroyable child of its block. vm.updateWith only pushes to the updating list, and only block opcodes go through didEnter, which calls associateDestroyable.
  4. When the block is destroyed, nothing reaches the opcode, so the destructor never runs.

The same leak happens whenever the dynamic modifier value changes to a different modifier. The replacement instance is attached to the orphaned opcode.

This dates from cb11136 (February 2021), so every Ember release since 3.25 is affected.

Earlier reports of the same bug:

This pull request is in two commits, so CI can show the failure first:

  1. Failing tests in the Glimmer integration suite and in the Ember rendering suite.
  2. The fix: register the updating opcode with the block before pushing it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Fvnp457DHuZC4fBa2KCiqB

A dynamic modifier whose value changes from undefined to a modifier
after the first render never runs its destructor when its block is
removed or when the render result is destroyed.

UpdateDynamicModifierOpcode attaches the new instance's destroyable to
itself with associateDestroyableChild(this, destroyable), but the opcode
is never registered as a destroyable child of its block. Only block
opcodes go through didEnter, which calls associateDestroyable.
vm.updateWith only pushes to the updating list.

Reported through universal-ember/ember-primitives#805, where the
Popover content element leaks @floating-ui/dom observers.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Fvnp457DHuZC4fBa2KCiqB
…al render

Register the UpdateDynamicModifierOpcode as a destroyable child of its
block. Instances that the opcode creates on update are attached to the
opcode with associateDestroyableChild, so the block now reaches them
when it is destroyed.

Fixes the leak reported in universal-ember/ember-primitives#805.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Fvnp457DHuZC4fBa2KCiqB
@NullVoxPopuli-ai-agent

Copy link
Copy Markdown
Contributor Author

CI on the test-only commit (14f95ce) failed on exactly the three new tests and nothing else: https://github.com/emberjs/ember.js/actions/runs/33908583452. The fix is now pushed as the second commit (d8a8382). It needs one more workflow approval.

@NullVoxPopuli NullVoxPopuli changed the title [BUGFIX beta] Destroy dynamic modifiers that were set after the initial render [BUGFIX lts] Destroy dynamic modifiers that were set after the initial render Sep 4, 2026
(owner) => {
return new this.CustomModifierManager(owner);
},
class extends EmberObject {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we be making new tests using EmberObject?

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.

I do want to get the EmberObjects out of the tests soon.

This is a shortcut for the secret static create(...) behavior that all the framework objects want

e.g.:

Image Image

@kategengler

Copy link
Copy Markdown
Member

One comment but otherwise 👍

@NullVoxPopuli
NullVoxPopuli merged commit c09b319 into emberjs:main Sep 4, 2026
50 checks passed
@NullVoxPopuli
NullVoxPopuli deleted the nvp/fix-dynamic-modifier-teardown branch September 4, 2026 20:44
@github-actions github-actions Bot mentioned this pull request Sep 4, 2026
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.

Values used as modifiers from nested function invocations need to have associateDestroyableChild called on them

3 participants