Skip to content

Svelte: Fix Svelte CSF code snippet crash on null args - #36770

Merged
ghengeveld merged 1 commit into
storybookjs:nextfrom
bryce-easygo:fix/svelte-csf-null-arg-snippet
Oct 14, 2026
Merged

ghengeveld merged 1 commit into
storybookjs:nextfrom
bryce-easygo:fix/svelte-csf-null-arg-snippet

Conversation

@bryce-easygo

Copy link
Copy Markdown
Contributor

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 null arg directly (icon={args.icon} or {args.icon}) threw from the source snippet emitter:

TypeError: Cannot read properties of null (reading 'Symbol(svelte.snippet)')

valueToString read Symbol.for('svelte.snippet') off any typeof 'object' value, and typeof null is 'object'. The story still rendered, but the error escaped from StoryRenderer's emitCode effect as an uncaught error and no snippet was emitted. {...args} was never affected because argsToProps drops null before calling valueToString, which is why the existing "all types of values" test passes with someNull: null.

The fix adds a null check, so a directly referenced null arg emits icon={null} / {null} like any other JSON value. The new unit test fails on next without it.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

  1. Run a sandbox: yarn task --task sandbox --start-from auto --template svelte-vite/default-ts
  2. Add a .stories.svelte file whose defineMeta sets args: { label: null } and whose story template renders <Button label={args.label} />
  3. Open that story's docs page (add tags: ['autodocs'] to defineMeta if the sandbox doesn't already) and check the source block shows <Button label={null} />, with no Cannot read properties of null (reading 'Symbol(svelte.snippet)') error in the browser console

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Declare whether manual QA will be needed for this PR during the next release, through qa:needed or qa:skip

  • Make 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

…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>
@coderabbitai

coderabbitai Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 21ef7b4a-5196-4efd-8fe8-4c2115282aa3
📥 Commits

Reviewing files that changed from the base of the PR and between 8af3851 and 2ae790b.

📒 Files selected for processing: 2
  • code/renderers/svelte/src/svelte-csf/runtime/emit-code.test.ts
  • code/renderers/svelte/src/svelte-csf/runtime/emit-code.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The 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.

Changes

Svelte null emission

Layer / File(s) Summary
Null value emission
code/renderers/svelte/src/svelte-csf/runtime/emit-code.ts, code/renderers/svelte/src/svelte-csf/runtime/emit-code.test.ts
The emitter checks for a non-null value before checking for the Svelte snippet marker. The regression test expects null in both the attribute and text child without an exception.

Priority: ⬇️ Low

Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 2ae79

Null-valued arguments can be emitted in the tested attribute and text-child cases; no unresolved merge-blocking risk remains.

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@shilman

shilman commented Oct 14, 2026

Copy link
Copy Markdown
Member

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.

@ghengeveld ghengeveld added bug ci:normal Run our default set of CI jobs (choose this for most PRs). qa:skip Pull Requests that do not need any QA. (e.g. documentation) labels Oct 14, 2026
@ghengeveld
ghengeveld merged commit e9933b5 into storybookjs:next Oct 14, 2026
143 of 152 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 14, 2026
2 tasks done
@bryce-easygo
bryce-easygo deleted the fix/svelte-csf-null-arg-snippet branch October 14, 2026 10:55
ghengeveld added a commit to storybookjs/sandboxes that referenced this pull request Oct 14, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-scan:human bug ci:normal Run our default set of CI jobs (choose this for most PRs). qa:skip Pull Requests that do not need any QA. (e.g. documentation)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants