#36423·storybook

[Bug]: Angular (angular-vite): switching a toolbar global on a docs page logs NG05104 once per story

Author: nuriddin2468Created Sep 24, 2026Updated Sep 28, 2026
Labelsbugangularaddon: docsaddon: toolbarsbuilder-vitesev:S4

Describe the bug

With @storybook/angular-vite 10.6.0, switching any toolbar global (for example a theme) while a docs page is open logs NG05104 once per Angular story on the page:

ERROR RuntimeError: NG05104: The selector "greeting--world[greeting-world-3]" did not match any elements.
ERROR RuntimeError: NG05104: The selector "greeting--storybook[greeting-storybook-1]" did not match any elements.

The page renders correctly afterwards; only the errors are wrong. Story mode is not affected. It happens with autodocs and with MDX pages (<Meta of>), with the default docs container and with a custom one. 11.0.0-alpha.1 has the same renderer code.

Reproduction link

https://github.com/nuriddin2468/storybook-angular-vite-docs-ng05104

Reproduction steps

  1. npm install && npm run storybook in the reproduction (Angular 22.1.7, Storybook 10.6.0, one component, two stories, autodocs, one theme toolbar global).
  2. Open http://localhost:6006/?path=/docs/greeting--docs. Both stories render, no error.
  3. Switch Theme from light to dark.
  4. The console shows one NG05104 per story.

Expected: no error.

System

bash
Storybook Environment Info:

  System:
    OS: macOS 15.7.7
    CPU: (11) arm64 Apple M3 Pro
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.21.0
    npm: 11.19.0 <----- active
    pnpm: 10.26.1
  Browsers:
    Chrome: 153.0.8010.53
    Safari: 26.2
  npmPackages:
    @storybook/addon-docs: 10.6.0 => 10.6.0
    @storybook/angular-vite: 10.6.0 => 10.6.0
    storybook: 10.6.0 => 10.6.0

Additional context

Cause, traced in the browser with the channel events and a mutation observer:

  • Preview.onUpdateGlobals re-renders every story render (storyRenders.map((r) => r.rerender())). Without waiting for those, PreviewWithSelection.onUpdateGlobals re-renders the docs page, and addon-docs' DocsRenderer remounts the whole page (key: Math.random()), which removes the story containers.
  • AbstractRenderer.render in @storybook/angular-vite writes the story's host element into its container, then queues bootstrapApplication (queueBootstrapping, one bootstrap at a time).
  • The re-renders from the first step are still in the queue when the remount removes their containers. When the queue reaches them, bootstrapApplication looks for a host that is no longer in the document: NG05104. The remount's own renders then bootstrap normally, which is why the page ends up correct.

React stories render synchronously, so the double render has no visible effect there.

A fix we apply locally as a pnpm patch of 10.6.0 (dist/_browser-chunks/chunk-UJ3I56EP.js, AbstractRenderer.render): keep the host element written before queueing, and skip the bootstrap when it is no longer connected, since a newer render owns the new host.

diff
-    let applicationRef = await queueBootstrapping(() => bootstrapApplication(application, {
+    let hostElement = targetDOMNode.querySelector(componentSelector);
+    let applicationRef = await queueBootstrapping(() => hostElement?.isConnected ? bootstrapApplication(application, {
       ...storyFnAngular.applicationConfig,
       providers
-    }));
-    applicationRefs.set(targetDOMNode, applicationRef);
+    }) : Promise.resolve(void 0));
+    applicationRef !== void 0 && applicationRefs.set(targetDOMNode, applicationRef);

With it applied to the reproduction, three theme switches on the docs page log no NG05104 and every story renders. Fixing the double render in onUpdateGlobals (re-render either the stories or the docs page, not both) would address the root cause for every renderer.