Repository navigation
Svelte: Fix Svelte CSF code snippet crash on null args - #36770
Conversation
…SF snippets
valueToString read Symbol.for('svelte.snippet') off any typeof 'object'
value, so a null arg referenced as args.x threw instead of emitting null.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe Svelte code emitter now handles null values without treating them as snippets. A regression test checks null output in an attribute and a text child. ChangesSvelte null emission
Priority: ⬇️ Low Severity of issue fixed: Low Merge Risk: ⚪ Minimal · up to
|
|
Thanks @bryce-easygo ! We're actively working on Svelte CSF and will expedite this fix. AFAIK the monorepo changes are for the SB11 version and we'll need to backport your changes to the satellite repo if you're using SB10. But we'll take care of it if that's the case. |
Check the diff here: storybookjs/storybook@8af3851...50a8282 List of included PRs since previous version: - storybookjs/storybook#36301 (sharadvc/cursor/fix-mcp-connect-agents-link-6fef) - storybookjs/storybook#35863 (SnowingFox/fix/35862-server-channel-error-handler) - storybookjs/storybook#36688 (ghengeveld/vitest-36221-leftovers) - storybookjs/storybook#36746 (fix/bbc-local-story-manifest-snippets) - storybookjs/storybook#36588 (fix/nextjs-router-mock-bfcache) - storybookjs/storybook#36391 (agent/sto-492-eslint-cjs) - storybookjs/storybook#36751 (agent/sto-280-prerelease-version-alignment) - storybookjs/storybook#36768 (svelte-knip-cleanup) - storybookjs/storybook#35834 (FrancoKaddour/fix/docgen-typescript7-missing-compiler-api) - storybookjs/storybook#36770 (bryce-easygo/fix/svelte-csf-null-arg-snippet)
Reported first as storybookjs/addon-svelte-csf#372, before I saw the addon had moved into core.
What I did
A Svelte CSF story that references a
nullarg directly (icon={args.icon}or{args.icon}) threw from the source snippet emitter:valueToStringreadSymbol.for('svelte.snippet')off anytypeof 'object'value, andtypeof nullis'object'. The story still rendered, but the error escaped fromStoryRenderer'semitCodeeffect as an uncaught error and no snippet was emitted.{...args}was never affected becauseargsToPropsdropsnullbefore callingvalueToString, which is why the existing "all types of values" test passes withsomeNull: null.The fix adds a
nullcheck, so a directly referencednullarg emitsicon={null}/{null}like any other JSON value. The new unit test fails onnextwithout it.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
yarn task --task sandbox --start-from auto --template svelte-vite/default-ts.stories.sveltefile whosedefineMetasetsargs: { label: null }and whose story template renders<Button label={args.label} />tags: ['autodocs']todefineMetaif the sandbox doesn't already) and check the source block shows<Button label={null} />, with noCannot read properties of null (reading 'Symbol(svelte.snippet)')error in the browser consoleDocumentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsDeclare whether manual QA will be needed for this PR during the next release, through
qa:neededorqa:skipMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.AI disclosure: written with Claude Code.
🤖 Generated with Claude Code