storybookjs / storybook

Storybook is a frontend workshop for building UI components and pages in isolation. Made for UI development, testing, and documentation.

Home Page:https://storybook.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] Angular: Support zoneless

valentinpalkovic opened this issue · comments

Discussed in #28400

Originally posted by valentinpalkovic July 1, 2024

Is your feature request related to a problem? Please describe.

Currently, Storybook always uses zone.js for change detection.

Describe the solution you'd like

Angular has introduced an experimental feature called zoneless.
The main benefit is that users can remove Zone.js to

  • Improved performance
  • Improved Core Web Vitals
  • Improved debugging experience
  • Better ecosystem compatibility

The solution would be to enable experimental zoneless mode in Storybook by setting an experimental flag in Storybook's Angular builder options

// angular.json
{
  "storybook": {
      "builder": "@storybook/angular:start-storybook",
      "options": {
         ...
         "experimentalZoneless": true
       }
   },
   "build-storybook": {
      "builder": "@storybook/angular:build-storybook",
      "options": {
            ...
            "experimentalZoneless": true
       }
    }
}

Tasklist

const applicationRef = await queueBootstrapping(() => {
      return bootstrapApplication(application, {
        ...storyFnAngular.applicationConfig,
        providers: [
+        // Consider, that `provideExperimentalZonelessChangeDetection` cannot be imported "normally", because former Angular versions do not provide this export. A conditional dynamic import will be necessary
+        experimentalZoneless ? provideExperimentalZonelessChangeDetection() : null          
          storyPropsProvider(newStoryProps$),
          ...analyzedMetadata.applicationProviders,
          ...(storyFnAngular.applicationConfig?.providers ?? []),
-        ],
+        ].filter(Boolean),
      });
    });

Acceptance criteria

  • If a user does not have zone.js in angular.json's <project>/architect/build/polyfills array defined AND the experimentalZoneless option is set in <project>/architect/storybook|build-storybook/options, Storybook and change detection via control changes should work.

Development workflow

Describe alternatives you've considered

No response

Are you able to assist to bring the feature to reality?

As a maintainer I can support contributors to implement this feature if questions arise.

Additional context

No response

Does someone want to work on it? I appreciate any help and can provide any guidance.