Skip to content

fix: apply static value attribute as textarea content on CSR - #18627

Open
sankalpsthakur wants to merge 1 commit into
sveltejs:mainfrom
sankalpsthakur:fix/18574-textarea-value
Open

fix: apply static value attribute as textarea content on CSR#18627
sankalpsthakur wants to merge 1 commit into
sveltejs:mainfrom
sankalpsthakur:fix/18574-textarea-value

Conversation

@sankalpsthakur

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. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • 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).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Fixes #18574

Problem

Static value on <textarea> was inconsistent between CSR and SSR:

Case CSR SSR
<textarea value="hi"> empty hi
<textarea value={'hi'}> hi hi

Browsers ignore the value HTML attribute on <textarea> (only child text content or the JS value property matter). The client compiler was baking static values into the template as value="hi", which is a no-op.

Fix

When compiling a static text value attribute on <textarea>, emit the value as template child text (with the same leading-newline and HTML-escape handling as the SSR path) instead of as an attribute. Dynamic value={...} already uses $.set_value and is unchanged.

Compiled client output goes from:

var root = $.from_html(`<textarea value="hi"></textarea>`);

to:

var root = $.from_html(`<textarea>hi</textarea>`);

defaultValue SSR remains out of scope here (tracked separately, e.g. #18446 / related PRs).

Tests

  • runtime-runes/samples/textarea-static-value — static attr, static expression, dynamic, children, leading newline, escaped content; asserts value and defaultValue
  • server-side-rendering/samples/textarea-static-value — expected HTML for static/dynamic/escaped cases

Local: FILTER=/textarea/ pnpm test and FILTER=textarea-static-value pnpm test pass.


AI disclosure: This contribution was prepared with assistance from an LLM-based coding agent. The change was reviewed and verified locally (repro, targeted tests) before opening the PR.

Browsers ignore the value HTML attribute on <textarea>, so static
value="..." was a no-op on client-side rendering while SSR and dynamic
value={...} already worked. Emit the static value as child text in the
template (matching SSR) so value and defaultValue are set.

Fixes sveltejs#18574
@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 7, 2026

Copy link
Copy Markdown

Install the latest version of svelte from 4439916:

pnpm add https://pkg.svelte.dev/svelte/c/44399162f42761a8b0805751e66820a229dba6fb

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/svelte/pr/18627

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4439916

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

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.

<textarea> value handling inconsistencies

1 participant