Skip to content

fix: avoid unnecessary stringify in server attributes#18232

Merged
Rich-Harris merged 2 commits into
sveltejs:mainfrom
Sean-Kenneth-Doherty:codex/optimize-server-attribute-stringify
May 18, 2026
Merged

fix: avoid unnecessary stringify in server attributes#18232
Rich-Harris merged 2 commits into
sveltejs:mainfrom
Sean-Kenneth-Doherty:codex/optimize-server-attribute-stringify

Conversation

@Sean-Kenneth-Doherty

Copy link
Copy Markdown
Contributor

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. Fixes Unnecessarily calling $.stringify on strings #10031.
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

What this changes

Server attribute template generation currently wraps each dynamic expression in $.stringify, even when the compiler can prove the expression is a string or a known constant. This reuses the existing scope evaluation metadata so server output can avoid $.stringify for proven string/constant chunks while keeping it for possibly nullish unknown values.

The updated snapshot covers a mixed attribute with a known string, mutable state, null, numeric/undefined constants, a known string-producing typeof, and an unknown prop value.

Tests and linting

  • pnpm test snapshot -t nullish-coallescence-omittance
  • pnpm test snapshot
  • pnpm --filter svelte check
  • pnpm lint
  • pnpm prettier --check .changeset/slow-bikes-serve.md

@changeset-bot

changeset-bot Bot commented May 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5299073

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Sean-Kenneth-Doherty Sean-Kenneth-Doherty marked this pull request as ready for review May 16, 2026 22:59
Comment thread .changeset/slow-bikes-serve.md Outdated

@Rich-Harris Rich-Harris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@Rich-Harris Rich-Harris merged commit a5df661 into sveltejs:main May 18, 2026
5 of 6 checks passed
@github-actions github-actions Bot mentioned this pull request May 18, 2026
dummdidumm pushed a commit that referenced this pull request May 20, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## svelte@5.55.9

### Patch Changes

- fix: don't unset batch when calling `{#await ...}` promise
([#18243](#18243))

- fix: promise-ify `{#await await ...}` expressions on the server and
correctly hydrate them on the client
([#18243](#18243))

- fix: deduplicate dependencies that are added outside the init/update
cycle ([#18243](#18243))

- fix: avoid false-positive batch invariant error
([#18246](#18246))

- fix: inline primitive constants in attribute values during SSR
([#18232](#18232))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unnecessarily calling $.stringify on strings

2 participants