Skip to content

Commit

Permalink
add faq to a11y test page about RSC and async components
Browse files Browse the repository at this point in the history
  • Loading branch information
winkerVSbecks committed Dec 20, 2024
1 parent 756d49e commit 7fad7e9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/content/notInNavigation/accessibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,32 @@ Chromatic builds upon Storybook's accessibility testing by providing automated t
No, automated testing catches a subset of accessibility issues. Manual testing is still recommended for comprehensive accessibility compliance.

</details>

<details>
<summary>Why don't the accessibility results show violations, even though I know there are some?</summary>

Modern React components often use asynchronous techniques like Suspense or React Server Components (RSC) to handle complex data fetching and rendering. These components don’t immediately render their final UI state. Storybook doesn’t inherently know when an async component has fully rendered. As a result, the a11y addon sometimes run too early, before the component finishes rendering, leading to false negatives (no reported violations even if they exist).

This only impacts users using:
* Storybook 8.5+
* Async components (RSC, or using Suspense or similar)
* Stories without a play function that awaits for the final component state

To address this issue, enable the `developmentModeForBuild` feature flag. This sets `process.env.NODE_ENV` to `development` when building your Storybooks. This ensures that React’s `act` utility is used, which helps ensure that all updates related to a test are processed and applied before making assertions.

```ts title=".storybook/main.ts"
// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
import type { StorybookConfig } from '@storybook/your-framework';

const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
features: {
developmentModeForBuild: true,
},
};

export default config;
```

</details>

0 comments on commit 7fad7e9

Please sign in to comment.