Skip to content

Angular: Skip the runtime source decorator when the docgen server produces snippets - #35906

Merged
valentinpalkovic merged 1 commit into
nextfrom
valentin/angular-docs-decorator-gate
Aug 17, 2026
Merged

valentinpalkovic merged 1 commit into
nextfrom
valentin/angular-docs-decorator-gate

Conversation

@valentinpalkovic

Copy link
Copy Markdown
Contributor

Follow-up to #35807.

What I did

With experimentalDocgenServer on, Angular produces two different code snippets for the same story: the story-docs snippet the server builds (a TypeScript host component) and the HTML template the runtime sourceDecorator computes in a post-render effect.
Both are pushed to the manager over the same SNIPPET_RENDERED channel event.
The Source block is safe because it reads the story-docs service directly and prefers it, but the Code panel keeps whichever event arrives last, so what it shows depends on which emit wins the race - while the panel is labelled ts either way.

This gates the decorator on the feature flag, the way @storybook/react already gates jsxDecorator, so exactly one producer is registered.

Before

experimentalDocgenServer: true

core/story-docs (server)          ┌────────────▶ Source block ─── serviceSnippet || snippet ──▶ TS host component
  TS host component ── beforeEach ┤
                  emitTransformCode└──┐
                                      ├── last SNIPPET_RENDERED wins ──▶ Code panel ──▶ whichever landed second
sourceDecorator ─────── useEffect ────┘
  <my-cmp [label]="…">
                  emitTransformCode

After

experimentalDocgenServer: true            experimentalDocgenServer: false

core/story-docs (server)                  sourceDecorator
  TS host component, or                     <my-cmp [label]="…">
  parameters.docs.source.originalSource
        │ beforeEach                              │ useEffect
        │ emitTransformCode                       │ emitTransformCode
        ├──▶ Source block                         ├──▶ Source block
        └──▶ Code panel                           └──▶ Code panel

The decision, in code/frameworks/angular-vite/src/client/docs/config.ts:

-const language = globalThis.FEATURES?.experimentalDocgenServer ? 'ts' : 'html';
+const useStaticServiceSnippets = globalThis.FEATURES?.experimentalDocgenServer === true;

 export const parameters: Parameters = {
   docs: {
     source: {
       type: SourceType.DYNAMIC,
-      language,
+      language: useStaticServiceSnippets ? 'ts' : 'html',
     },
   },
 };

-export const decorators: DecoratorFunction[] = [sourceDecorator];
+export const decorators: DecoratorFunction[] = useStaticServiceSnippets ? [] : [sourceDecorator];

What no longer holds

With the docgen server on, the runtime template no longer reaches the Source block or the Code panel at all, under any timing.
For a story the analyzer produces no snippet for, both surfaces now fall back to raw CSF (parameters.docs.source.originalSource, emitted by the same beforeEach hook) instead of the runtime template.
That is the same trade-off @storybook/react already makes under this flag.

With the flag off, nothing changes.

What a bad run looks like

Reverting the decorator gate while keeping the tests:

 FAIL  src/client/docs/config.test.ts > docs decorators > drops the runtime source decorator when the docgen server produces snippets
AssertionError: expected [ [Function sourceDecorator] ] to deeply equal []

- Expected
+ Received

- []
+ [
+   [Function sourceDecorator],
+ ]

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

  1. Run the docgen-server sandbox: yarn task --task sandbox --start-from auto --template angular-vite/docgen-server-ts
  2. The Code panel is opt-in, so add it to the sandbox's .storybook/preview.ts:
    export const parameters = { docs: { codePanel: true } };
  3. Open Example / Button → Primary and select the Code panel.
  4. The panel shows the TypeScript host component (a @Component class binding the story's args), highlighted as TypeScript. It must never show the <storybook-button …> HTML template, and it must not flip between the two across reloads or navigation between stories.
  5. Open the Docs tab for the same component and expand Show code under the story. It shows the same TypeScript host component.
  6. Run the stock sandbox: yarn task --task sandbox --start-from auto --template angular-vite/default-ts
  7. Repeat steps 2-5. Both surfaces now show the <storybook-button …> HTML template, highlighted as HTML, exactly as before this PR.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update MIGRATION.MD

No documentation change: this is internal wiring behind the experimental experimentalDocgenServer flag, and the user-facing behaviour it describes (server snippets replace the runtime template) is what was already documented.

@github-actions

github-actions Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor
Fails
🚫

PR is not labeled with one of: ["qa:needed","qa:skip","qa:success"]

Generated by 🚫 dangerJS against 6e29dc5

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f5b85d6b-07fb-416a-acd2-5450447ec7ef

📥 Commits

Reviewing files that changed from the base of the PR and between 7f28076 and 6e29dc5.

📒 Files selected for processing (2)
  • code/frameworks/angular-vite/src/client/docs/config.test.ts
  • code/frameworks/angular-vite/src/client/docs/config.ts

Walkthrough

The Angular docs configuration now selects static TypeScript snippets when the experimental docgen server feature is exactly true. It removes the runtime source decorator in that mode and retains HTML snippets and the decorator otherwise. Tests cover enabled, disabled, and unset states.

Changes

Angular documentation snippet configuration

Layer / File(s) Summary
Static snippet configuration and coverage
code/frameworks/angular-vite/src/client/docs/config.ts, code/frameworks/angular-vite/src/client/docs/config.test.ts
The configuration selects ts and no decorators when FEATURES.experimentalDocgenServer is exactly true. Other states select html and retain sourceDecorator. Tests cover each state.

Merge Risk: ⚪ Minimal · up to 6e29d

This narrowly gates the runtime source decorator behind the experimental docgen-server flag, preserving existing behavior when the flag is off and preventing competing snippet producers when it is on; no actionable merge-blocking risk remains beyond normal checks and review.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@valentinpalkovic valentinpalkovic added the ci:normal Run our default set of CI jobs (choose this for most PRs). label Aug 14, 2026
@valentinpalkovic valentinpalkovic self-assigned this Aug 14, 2026
@valentinpalkovic valentinpalkovic added ci:normal Run our default set of CI jobs (choose this for most PRs). and removed ci:normal Run our default set of CI jobs (choose this for most PRs). labels Aug 17, 2026
@storybook-app-bot

Copy link
Copy Markdown
Contributor

Package Benchmarks

Commit: 6e29dc5, ran on 17 August 2026 at 07:00:46 UTC

The following packages have significant changes to their size or dependencies:

@storybook/cli

Before After Difference
Dependency count 205 205 0
Self size 843 KB 843 KB 0 B
Dependency size 86.39 MB 86.53 MB 🚨 +141 KB 🚨
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 198 198 0
Self size 44 KB 44 KB 0 B
Dependency size 84.86 MB 85.00 MB 🚨 +141 KB 🚨
Bundle Size Analyzer Link Link

@valentinpalkovic
valentinpalkovic merged commit 7a52b1f into next Aug 17, 2026
158 of 165 checks passed
@valentinpalkovic
valentinpalkovic deleted the valentin/angular-docs-decorator-gate branch August 17, 2026 07:18
huang-julien added a commit to storybookjs/sandboxes that referenced this pull request Aug 18, 2026
Check the diff here: storybookjs/storybook@f96ed20...add38a0

List of included PRs since previous version:
- storybookjs/storybook#35922 (valentin/sb-1766-angular-docgen-documentation-pass)
- storybookjs/storybook#35844 (s-robertson/u/srobertson/fix-react-component-meta-union-props)
- storybookjs/storybook#35931 (valentin/sb-1847-componentid-collision-warning)
- storybookjs/storybook#35923 (valentin/sb-1789-server-side-code-snippets-resolve-spreads-and-identifier)
- storybookjs/storybook#35940 (valentin/sb-1789-review-fixes)
- storybookjs/storybook#35900 (julien/vue-api-description)
- storybookjs/storybook#35938 (fix-publish-ansi-parsing)
- storybookjs/storybook#35929 (valentin/sb-1821-pin-oxc-resolver)
- storybookjs/storybook#35936 (chore/changelog-v10.5.9)
- storybookjs/storybook#35930 (valentin/sb-1789-review-fixes)
- storybookjs/storybook#35921 (valentin/sb-1809-bug-angular-constructor-and-generic-function-inputs-lose-the)
- storybookjs/storybook#35917 (norbert/fix-publish-staged-retries)
- storybookjs/storybook#35896 (valentin/sb-1776-angular-docs-end-to-end)
- storybookjs/storybook#35920 (julien/vue_server_docgen_options)
- storybookjs/storybook#35907 (valentin/docgen-server-arg-types)
- storybookjs/storybook#35886 (valentin/sb-1799-default-docgen-server-angular-vite)
- storybookjs/storybook#35902 (fix/vue-snippet-runtimeoverride)
- storybookjs/storybook#35825 (norbert/module-graph-skip-noop-mirror)
- storybookjs/storybook#35629 (reuben/fix-pseudo-states-cssom-rewrites)
- storybookjs/storybook#35915 (next-merge-prerelease)
- storybookjs/storybook#35906 (valentin/angular-docs-decorator-gate)
- storybookjs/storybook#35830 (version-non-patch-from-10.6.0-alpha.5)
- storybookjs/storybook#35899 (valentin/angular-required-input-with-default)
- storybookjs/storybook#35831 (norbert/spike-module-graph-hot-cold-split)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

angular bug ci:normal Run our default set of CI jobs (choose this for most PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants