Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 10.3.1

- CLI: Use npm info to fetch versions in repro command - [#34214](https://github.com/storybookjs/storybook/pull/34214), thanks @yannbf!
- Core: Prevent story-local viewport from persisting in URL - [#34153](https://github.com/storybookjs/storybook/pull/34153), thanks @ghengeveld!

## 10.3.0

_> Improved developer experience, AI-assisting tools, and broader ecosystem support_
Expand Down
12 changes: 5 additions & 7 deletions code/core/src/manager-api/modules/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,20 @@ export const init: ModuleFn<SubAPI, SubState> = ({ store, fullAPI, provider }) =
SET_GLOBALS,
function handleSetGlobals(this: any, { globals, globalTypes }: SetGlobalsPayload) {
const { ref } = getEventMetadata(this, fullAPI)!;
const currentGlobals = store.getState()?.globals;
const currentUserGlobals = store.getState()?.userGlobals;

if (!ref) {
store.setState({ globals, userGlobals: globals, globalTypes });
} else if (Object.keys(globals).length > 0) {
logger.warn('received globals from a non-local ref. This is not currently supported.');
}

// If we have stored globals different to what the preview just inited with,
// we should update it to those values
if (
currentGlobals &&
Object.keys(currentGlobals).length !== 0 &&
!deepEqual(globals, currentGlobals)
currentUserGlobals &&
Object.keys(currentUserGlobals).length !== 0 &&
!deepEqual(globals, currentUserGlobals)
) {
api.updateGlobals(currentGlobals);
api.updateGlobals(currentUserGlobals);
}
}
);
Expand Down
28 changes: 27 additions & 1 deletion code/core/src/manager-api/tests/globals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('globals API', () => {
});
});

it('emits UPDATE_GLOBALS if retains a globals value different to what receives on SET_GLOBALS', () => {
it('emits UPDATE_GLOBALS if retains a user globals value different to what receives on SET_GLOBALS', () => {
const channel = new EventEmitter();
const listener = vi.fn();
channel.on(UPDATE_GLOBALS, listener);
Expand All @@ -83,6 +83,7 @@ describe('globals API', () => {
} as unknown as ModuleArgs);
store.setState({
...state,
userGlobals: { a: 'c' },
globals: { a: 'c' },
});

Expand All @@ -103,6 +104,31 @@ describe('globals API', () => {
});
});

it('does not push story globals to preview when SET_GLOBALS fires with empty globals', () => {
const channel = new EventEmitter();
const listener = vi.fn();
channel.on(UPDATE_GLOBALS, listener);

const store = createMockStore();
const { state } = initModule({
store,
provider: { channel },
} as unknown as ModuleArgs);
store.setState({
...state,
userGlobals: {},
storyGlobals: { viewport: 'mobile1' },
globals: { viewport: 'mobile1' },
});

channel.emit(SET_GLOBALS, {
globals: {},
globalTypes: {},
} satisfies SetGlobalsPayload);

expect(listener).not.toHaveBeenCalled();
});

it('ignores SET_STORIES from other refs', () => {
const channel = new EventEmitter();
const api = { findRef: vi.fn() };
Expand Down
8 changes: 4 additions & 4 deletions code/lib/cli-storybook/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { existsSync } from 'node:fs';
import { mkdir, readdir, rm } from 'node:fs/promises';
import { isAbsolute } from 'node:path';

import type { PackageManagerName } from 'storybook/internal/common';
import { PackageManagerName } from 'storybook/internal/common';
import {
JsPackageManagerFactory,
isCI,
Expand Down Expand Up @@ -42,10 +42,10 @@ export const sandbox = async ({
let selectedConfig: Template | undefined = TEMPLATES[filterValue as TemplateKey];
let templateId: Choice | null = selectedConfig ? (filterValue as TemplateKey) : null;

const { packageManager: pkgMgr } = options;

// Always use npm to fetch versions, as other package manager commands may fail when running in
// non-project directories (e.g. parent sandbox directory). We just need to use npm info for this use case.
const packageManager = JsPackageManagerFactory.getPackageManager({
force: pkgMgr,
force: PackageManagerName.NPM,
});
const latestVersion = (await packageManager.latestVersion('storybook'))!;
const nextVersion = (await packageManager.latestVersion('storybook@next')) ?? '0.0.0';
Expand Down
3 changes: 2 additions & 1 deletion code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,6 @@
"Dependency Upgrades"
]
]
}
},
"deferredNextVersion": "10.3.1"
}
2 changes: 1 addition & 1 deletion docs/versions/latest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"10.3.0","info":{"plain":""}}
{"version":"10.3.1","info":{"plain":"- CLI: Use npm info to fetch versions in repro command - [#34214](https://github.com/storybookjs/storybook/pull/34214), thanks @yannbf!\n- Core: Prevent story-local viewport from persisting in URL - [#34153](https://github.com/storybookjs/storybook/pull/34153), thanks @ghengeveld!"}}
2 changes: 1 addition & 1 deletion docs/versions/next.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"10.3.0-beta.3","info":{"plain":"- Addon-Vitest: Handle additional vitest config export patterns in postinstall - [#34106](https://github.com/storybookjs/storybook/pull/34106), thanks @copilot-swe-agent!\n- CLI: Add vike CLI metadata - [#34189](https://github.com/storybookjs/storybook/pull/34189), thanks @yannbf!\n- Maintenance: Revert pull request #33930 HMR events - [#34190](https://github.com/storybookjs/storybook/pull/34190), thanks @yannbf!\n- UI: Ensure Link without href is keyboard-reachable - [#34163](https://github.com/storybookjs/storybook/pull/34163), thanks @Sidnioulz!\n- UI: Zoom faster when pressing shift - [#34185](https://github.com/storybookjs/storybook/pull/34185), thanks @Sidnioulz!\n- Vite: Add mock entries to optimizeDeps.entries - [#34167](https://github.com/storybookjs/storybook/pull/34167), thanks @valentinpalkovic!"}}
{"version":"10.4.0-alpha.2","info":{"plain":"- CLI: Use npm info to fetch versions in repro command - [#34214](https://github.com/storybookjs/storybook/pull/34214), thanks @yannbf!\n- Core: Prevent story-local viewport from persisting in URL - [#34153](https://github.com/storybookjs/storybook/pull/34153), thanks @ghengeveld!\n- Maintenance: Remove dead-code copy of wrap-getAbsolutePath-utils - [#34168](https://github.com/storybookjs/storybook/pull/34168), thanks @mixelburg!\n- Security: Makes sure `serialize-javascript` is at latest version - [#34034](https://github.com/storybookjs/storybook/pull/34034), thanks @50bbx!"}}
Loading