Skip to content

a render that throws can leave a global tracking frame open for the rest of the test run. #21681

Closed

Description

@betocantu93

🐞 Describe the Bug

On ember-source 7.3.0 (development build), a render that throws can leave a global tracking frame open for the rest of the test run.

VM.execute's DEBUG error path cleans up in this order:

  1. it closes the open blocks (popBlock());
  2. then it calls resetTracking().

When popBlock() throws (its DOM is already gone), that exception escapes the finally, and resetTracking() never runs. CURRENT_TRACKER and the - While rendering: {ROOT} tracking transaction stay open. From then on, every tracked write fails as a backtracking assertion, in every later test, including unit tests that render nothing.

We hit it through @ember/test-helpers 5.7. Since ember-test-helpers#1580, render() and clearRender() go through renderComponent for ember-source >= 6.12.1. The sequence is:

  • A test's render() fails while installing a modifier (in TransactionImpl.commit). renderComponent exits before RENDER_CACHE.set(into, …).
  • The test's clearRender() renders into the same element. Nothing is cached for it, so renderComponent sets into.innerHTML = '' under the failed root, which is still registered.
  • The new render then fails in the VM. Unwinding its blocks throws NotFoundError: Failed to execute 'insertBefore' on 'Node', so tracking is never reset.

In our app's suite, one such test turned ~1,000 later tests red.

🔬 Minimal Reproduction

Two tests in one module, run in order in a Vite + Embroider app on ember-source 7.3.0 with @ember/test-helpers 5.7.0:

import { on } from '@ember/modifier';
import { tracked } from '@glimmer/tracking';
import { clearRender, render, resetOnerror, settled, setupOnerror } from '@ember/test-helpers';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';

class State {
  @tracked value = 0;
}

module('a render that throws', function (hooks) {
  setupRenderingTest(hooks);
  hooks.afterEach(() => resetOnerror());

  test('throws', async function (assert) {
    const errors = [];
    setupOnerror((e) => errors.push(e.message));
    try {
      await render(<template><button {{on "click" undefined}}>x</button></template>);
    } catch (e) {
      errors.push(e.message);
    }
    assert.true(errors[0]?.includes('to the `on` modifier'));
    try {
      await clearRender();
    } catch {}
  });

  test('the next test', async function (assert) {
    const state = new State();
    await render(<template>{{state.value}}</template>);
    state.value = 1;
    await settled();
    assert.dom().hasText('1');
  });
});

The test build must resolve Ember's development build (the development export condition). With vite build --mode development, Vite resolves production unless NODE_ENV=development, and the production build has no DEBUG path at all.

Right after the clearRender(), isTracking() from @glimmer/validator returns true, and debug.resetTrackingTransaction() returns "- While rendering:\n {ROOT}…".

😕 Actual Behavior

the next test fails, as does every test after it. In our app, the first tracked write in a test is ember-intl's (from an instance-initializer), so the next tests fail at boot:

Promise rejected before "the next test": Assertion Failed: You attempted to update `_intls` on `<IntlService:ember3>`,
but it had already been used previously in the same computation. ...
`_intls` was first used:
- While rendering:
  {ROOT}

Without that initializer, I'd expect the same assertion on the test's own state.value = 1. I only ran it in our app.

🤔 Expected Behavior

A render error stays in its own test. The VM's error cleanup always resets tracking, even when closing the open blocks throws, and the next test renders and updates normally.

🌍 Environment

  • Ember: ember-source 7.3.0 (dist/dev), @ember/test-helpers 5.7.0, ember-qunit 9.2.0
  • Ember-CLI: 7.3.0, building with Vite 8.3.2 / @embroider/vite 1.7.15 / @embroider/compat 4.1.27
  • Node.js/npm: Node 22.22.1, pnpm 12.9.1
  • OS: Linux (Docker sandbox)
  • Browser: Chrome 155 (headless, testem)

➕ Additional Context

Local fix (a pnpm patch on 7.3.0): wrap the popBlock loop in VM.execute's DEBUG finally in its own try/finally, so resetTracking() always runs:

} finally {
  if (hasErrored) {
    try {
      let elements = this.tree();
      while (elements.hasBlocks) elements.popBlock();
    } finally {
      console.error(`\n\nError occurred:\n\n${resetTracking()}\n\n`);
    }
  }
}

A second, related leak (separate from the cascade): renderComponent creates one renderer per owner (RENDER_CACHE/RENDERER_CACHE), but that renderer is never a destroyable child of the owner. If the first render throws, associateDestroyableChild(owner, …) is never reached. The renderer then stays in the global renderers list, and its root re-renders on every later run loop: the dev build logs "Attempted to rerender, but the Ember application has had an unrecoverable error occur during render…", and the prod build constructs the failed component again. We also patch this with associateDestroyableChild(owner, renderer) where the renderer is created. On its own, that change does not fix the reproduction above.

Results on the reproduction:

ember-source the next test
stock 7.3.0 fails, as does every later test
renderer change only fails
renderer change + resetTracking change passes

(I did not run the resetTracking change on its own.)

Related, but none of these covers this case:

Open questions:

  • Is try/finally around popBlock the right fix?
  • Should renderComponent also avoid clearing innerHTML / rendering under a root whose previous render failed?
  • Should the renderer renderComponent creates be a destroyable child of the owner?

Activity

  1. changed the title [-]Bug report[/-] [+]a render that throws can leave a global tracking frame open for the rest of the test run.[/+] on Oct 9, 2026
  2. NullVoxPopuli commented on Oct 9, 2026

    @NullVoxPopuli
    SponsorContributor

    have you tried with ember-source @ main?

  3. betocantu93 commented on Oct 9, 2026

    @betocantu93
    ContributorAuthor

    Thanks! I built main (eef7970b07) and ran our suite against it:

    • The cascade I reported doesn't happen on main. My two-test repro passes, and our full suite (~1,370 tests) has no backtracking cascade: 0 _intls failures, versus ~1,000 on 7.3.0. "Attempted to rerender…" warnings also drop from ~4,650 to 35. My guess is that [BUGFIX lts] Release renderComponent roots (and renderers) when the result is destroyed #21647 is what fixes it, though I haven't isolated it. Could that be backported to 7.3 / LTS?

    • The underlying hole is still on main, though. In VM.execute's DEBUG finally (packages/@glimmer/runtime/lib/vm/append.ts), if popBlock() throws while closing a block whose DOM is gone, resetTracking() is skipped. The tracking frame then stays open for every later render and update. Here is a minimal repro with no test-helpers involved. It fails on 7.3.0 and on main, and passes with a try/finally around the popBlock loop:

    import Component from '@glimmer/component';
    import { renderComponent } from '@ember/renderer';
    import { isTracking, resetTracking } from '@glimmer/validator';
    import { setupRenderingTest } from 'ember-qunit';
    import { module, test } from 'qunit';
    
    module('a render error whose cleanup throws', function (hooks) {
      setupRenderingTest(hooks);
    
      test('still resets tracking', async function (assert) {
        const element = document.createElement('div');
        const marker = document.createComment('marker');
        element.append(marker);
        document.querySelector('#ember-testing').append(element);
    
        class Boom extends Component {
          constructor(owner, args) {
            super(owner, args);
            marker.remove(); // the VM will close its block by inserting before this
            throw new Error('boom');
          }
    
          <template>never</template>
        }
    
        try {
          renderComponent(Boom, { into: { element, nextSibling: marker }, owner: this.owner });
        } catch {}
    
        const leaked = isTracking();
        resetTracking(); // don't leave it to the rest of the run
        assert.false(leaked, 'no tracking frame is left open');
      });
    });
    ember-source result
    7.3.0 fails: the frame is left open, and the "Error occurred" log never appears because resetTracking() didn't run
    main @ eef7970b07 fails, same as 7.3.0
    7.3.0 + the change below passes

    The change we're running as a pnpm patch:

    } finally {
      if (hasErrored) {
        try {
          let elements = this.tree();
          while (elements.hasBlocks) elements.popBlock();
        } finally {
          console.error(`\n\nError occurred:\n\n${resetTracking()}\n\n`);
        }
      }
    }
  4. betocantu93 commented on Oct 9, 2026

    @betocantu93
    ContributorAuthor

    This of course my friend is AI suggestions and findings while fixing our test suite when moving to ember 7.3

  5. NullVoxPopuli commented on Oct 9, 2026

    @NullVoxPopuli
    SponsorContributor

    are you experiencing this because tests are running in production mode?
    (sorry, AI makes too many words, and I get overwhelmed and quit)

  6. betocantu93 commented on Oct 10, 2026

    @betocantu93
    ContributorAuthor

    No, it's the development build. Our test build had been resolving Ember's prod build at first; after fixing that, the repro still fails on 7.3.0 and on main (dev builds). The bug is in VM.execute's DEBUG-only finally: if popBlock() throws, resetTracking() is skipped.

  7. added a commit that references this issue on Oct 10, 2026
    9203d38
  8. NullVoxPopuli commented on Oct 10, 2026

    @NullVoxPopuli
    SponsorContributor

    @betocantu93

    I noticed:

    const marker = document.createComment('marker');
    element.append(marker);

    what do you have that's doing that?

    generally this isn't a supported way of manipulating the DOM, and manual DOM manipulation with any SPA has a number of rough edges and is only supported in narrow use cases.

  9. betocantu93 commented on Oct 10, 2026

    @betocantu93
    ContributorAuthor

    Nothing in our app manipulates the DOM. The marker is only to force the failure in a small repro. In our suite the sequence was: a modifier threw during install ({{on "click" undefined}}), then test-helpers' clearRender() rendered into the same element, and that render failed with NotFoundError: insertBefore from popBlock() in VM.execute's cleanup. I didn't pin down which node was missing, but it seems to be the earlier failed render's DOM. Either way, the issue is that an exception while closing blocks skips resetTracking(), which leaves tracking broken for everything after it.

  10. added 2 commits that reference this issue on Oct 10, 2026
    58a36db
    23b6117
  11. NullVoxPopuli commented on Oct 10, 2026

    @NullVoxPopuli
    SponsorContributor

    in #21685, I've left enough context about this that future readers will know what's going on (hopefully).

    as this is a dev-time only fix, I'm pretty comfortable with the solution, and am OK with the test being a little goofy

  12. added 2 commits that reference this issue on Oct 10, 2026
    12f57d8
    482321a
  13. added 3 commits that reference this issue on Oct 13, 2026
    070f198
    428a167
    311ebab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions