Skip to content

Commit

Permalink
Merge pull request #30260 from storybookjs/version-non-patch-from-8.5…
Browse files Browse the repository at this point in the history
….0-beta.10

Release: Prerelease 8.5.0-beta.11
  • Loading branch information
valentinpalkovic authored Jan 14, 2025
2 parents 426586d + d83c397 commit 936c3e0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.prerelease.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 8.5.0-beta.11

- CLI: Update a11y-test comment with experimental caveat - [#30258](https://github.com/storybookjs/storybook/pull/30258), thanks @shilman!
- Manager API: Fix infinite render-loop caused by `useSharedState` - [#30259](https://github.com/storybookjs/storybook/pull/30259), thanks @JReinhold!

## 8.5.0-beta.10

- Addon A11y: Adjust default behaviour when using with experimental-addon-test - [#30162](https://github.com/storybookjs/storybook/pull/30162), thanks @valentinpalkovic!
Expand Down
28 changes: 19 additions & 9 deletions code/core/src/manager-api/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,17 @@ export function useSharedState<S>(stateId: string, defaultState?: S) {
}
}, [quicksync]);

const setState = async (s: S | API_StateMerger<S>, options?: Options) => {
await api.setAddonState<S>(stateId, s, options);
const result = api.getAddonState(stateId);
const setState = useCallback(
async (s: S | API_StateMerger<S>, options?: Options) => {
await api.setAddonState<S>(stateId, s, options);
const result = api.getAddonState(stateId);

STORYBOOK_ADDON_STATE[stateId] = result;
return result;
},
[api, stateId]
);

STORYBOOK_ADDON_STATE[stateId] = result;
return result;
};
const allListeners = useMemo(() => {
const stateChangeHandlers = {
[`${SHARED_STATE_CHANGED}-client-${stateId}`]: setState,
Expand Down Expand Up @@ -446,14 +450,20 @@ export function useSharedState<S>(stateId: string, defaultState?: S) {
}, [stateId]);

const emit = useChannel(allListeners);
return [
state,

const stateSetter = useCallback(
async (newStateOrMerger: S | API_StateMerger<S>, options?: Options) => {
await setState(newStateOrMerger, options);
const result = api.getAddonState(stateId);
emit(`${SHARED_STATE_CHANGED}-manager-${stateId}`, result);
},
] as [S, (newStateOrMerger: S | API_StateMerger<S>, options?: Options) => void];
[api, emit, setState, stateId]
);

return [state, stateSetter] as [
S,
(newStateOrMerger: S | API_StateMerger<S>, options?: Options) => void,
];
}

export function useAddonState<S>(addonId: string, defaultState?: S) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ describe('addonA11yAddonTest', () => {
},
// The \`a11y-test\` tag controls whether accessibility tests are run as part of a standalone Vitest test run
// For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing#configure-accessibility-tests-with-the-test-addon
// The tag and its behavior are experimental and subject to change.
// For more information please see: https://storybook.js.org/docs/writing-tests/accessibility-testing#configure-accessibility-tests-with-the-test-addon
tags: [/*'a11y-test'*/]
};
Expand Down Expand Up @@ -740,7 +741,8 @@ describe('addonA11yAddonTest', () => {
const preview: Preview = {
// The \`a11y-test\` tag controls whether accessibility tests are run as part of a standalone Vitest test run
// For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing#configure-accessibility-tests-with-the-test-addon
// The tag and its behavior are experimental and subject to change.
// For more information please see: https://storybook.js.org/docs/writing-tests/accessibility-testing#configure-accessibility-tests-with-the-test-addon
tags: ["existingTag"/*, "a11y-test"*/],
parameters: {
controls: {
Expand Down Expand Up @@ -824,7 +826,8 @@ describe('addonA11yAddonTest', () => {
},
// The \`a11y-test\` tag controls whether accessibility tests are run as part of a standalone Vitest test run
// For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing#configure-accessibility-tests-with-the-test-addon
// The tag and its behavior are experimental and subject to change.
// For more information please see: https://storybook.js.org/docs/writing-tests/accessibility-testing#configure-accessibility-tests-with-the-test-addon
tags: [/*"a11y-test"*/]
};"
`);
Expand All @@ -850,7 +853,8 @@ describe('addonA11yAddonTest', () => {
expect(transformed).toMatchInlineSnapshot(`
"export default {
// The \`a11y-test\` tag controls whether accessibility tests are run as part of a standalone Vitest test run
// For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing#configure-accessibility-tests-with-the-test-addon
// The tag and its behavior are experimental and subject to change.
// For more information please see: https://storybook.js.org/docs/writing-tests/accessibility-testing#configure-accessibility-tests-with-the-test-addon
tags: ["existingTag"/*, "a11y-test"*/],
parameters: {
controls: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export async function transformPreviewFile(source: string, filePath: string) {
const indentation = lines[tagsLineIndex]?.match(/^\s*/)?.[0];

// Add the comment with the same indentation level
const comment = `${indentation}// The \`a11y-test\` tag controls whether accessibility tests are run as part of a standalone Vitest test run\n${indentation}// For more information please visit: https://storybook.js.org/docs/writing-tests/accessibility-testing#configure-accessibility-tests-with-the-test-addon`;
const comment = `${indentation}// The \`a11y-test\` tag controls whether accessibility tests are run as part of a standalone Vitest test run\n${indentation}// The tag and its behavior are experimental and subject to change.\n${indentation}// For more information please see: https://storybook.js.org/docs/writing-tests/accessibility-testing#configure-accessibility-tests-with-the-test-addon`;
lines.splice(tagsLineIndex, 0, comment);

return formatFileContent(filePath, lines.join('\n'));
Expand Down
3 changes: 2 additions & 1 deletion code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,6 @@
"Dependency Upgrades"
]
]
}
},
"deferredNextVersion": "8.5.0-beta.11"
}
2 changes: 1 addition & 1 deletion docs/versions/next.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"8.5.0-beta.10","info":{"plain":"- Addon A11y: Adjust default behaviour when using with experimental-addon-test - [#30162](https://github.com/storybookjs/storybook/pull/30162), thanks @valentinpalkovic!\n- Addon A11y: Change default element selector - [#30253](https://github.com/storybookjs/storybook/pull/30253), thanks @valentinpalkovic!\n- Addon Docs: Make new code panel opt in - [#30248](https://github.com/storybookjs/storybook/pull/30248), thanks @shilman!\n- Addon Test: Fix generated path to `vitest.setup.js` - [#30233](https://github.com/storybookjs/storybook/pull/30233), thanks @JReinhold!"}}
{"version":"8.5.0-beta.11","info":{"plain":"- CLI: Update a11y-test comment with experimental caveat - [#30258](https://github.com/storybookjs/storybook/pull/30258), thanks @shilman!\n- Manager API: Fix infinite render-loop caused by `useSharedState` - [#30259](https://github.com/storybookjs/storybook/pull/30259), thanks @JReinhold!"}}

0 comments on commit 936c3e0

Please sign in to comment.