Skip to content

fix: assign dev element locations at template creation on the client - #19291

Merged
dummdidumm merged 4 commits into
mainfrom
fix/svelte-meta-client-locations
Nov 17, 2026
Merged

dummdidumm merged 4 commits into
mainfrom
fix/svelte-meta-client-locations

Conversation

@baseballyama

Copy link
Copy Markdown
Member

Follow-up to #19287.

#19287 moved $.add_locations to the end of each template's body, so that during hydration the elements of child components (which aren't delimited by hydration markers) already have their __svelte_meta and can be skipped.

On the client, though, assign_locations doesn't track depth, so at the end of the body the walk also sees everything that blocks and child components have inserted into the template. Any such element that doesn't have __svelte_meta takes the location of the following element, which in turn ends up with no location. Before #19287 this couldn't happen on the client, because locations were assigned right after cloning, when the template only contains its own elements.

Two cases that regressed (both are added as tests that fail on main):

  • a raw snippet rendered as a <svelte:boundary>'s pending snippet. createRawSnippet only sets __svelte_meta when dev_stack isn't null, and it is null there:

    <output>
    	<svelte:boundary {pending}>
    		{await new Promise(() => {})}
    	</svelte:boundary>
    	<p>after</p>
    </output>
    before fix: assign __svelte_meta after components properly #19287 main
    <section> (raw snippet) – main.svelte:13:1 (the <p>'s location)
    <p> main.svelte:13:1 –
  • a component that wasn't compiled in dev mode (or any function that inserts elements without __svelte_meta): its element takes the location of the element after it, and that element gets none.

This PR assigns the locations right after the template is created on the client (as before), and only defers the assignment to the end of the body while hydrating. The locations array is hoisted so it isn't duplicated between the two calls:

var locations = [[5, 0], [7, 0]];

// ...
var fragment = root();
$.add_locations(fragment, Main[$.FILENAME], locations); // no-op while hydrating
// ...
$.add_hydration_locations(fragment, Main[$.FILENAME], locations); // no-op unless hydrating
$.append($$anchor, fragment);

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

🤖 Generated with Claude Code

https://claude.ai/code/session_01MNFNHpae1SEriX7anW4ChC

#19287 moved `add_locations` to the end of each template's body so that,
during hydration, elements of child components can be skipped. On the
client, though, the walk doesn't track depth, so by that time it also sees
everything blocks and child components have inserted, and any such element
without `__svelte_meta` (a raw snippet rendered by a boundary, a component
not compiled in dev mode...) takes the location of the following element.

Assign locations right after the template is created on the client, as
before, and only defer the assignment while hydrating.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MNFNHpae1SEriX7anW4ChC
Copilot AI balanced review requested due to automatic review settings November 17, 2026 16:05
@pkg-svelte-dev

pkg-svelte-dev Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Install the latest version of svelte from e470960:

pnpm add https://pkg.svelte.dev/svelte/c/e4709606645049dcef2d6c60a3e2db22b26e0974

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

@changeset-bot

changeset-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e470960

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@baseballyama
baseballyama marked this pull request as draft November 17, 2026 16:09
@svelte-docs-bot

Copy link
Copy Markdown

@baseballyama
baseballyama marked this pull request as ready for review November 17, 2026 16:13

@dummdidumm dummdidumm 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.

👍

@dummdidumm
dummdidumm merged commit 75516a8 into main Nov 17, 2026
16 checks passed
@dummdidumm
dummdidumm deleted the fix/svelte-meta-client-locations branch November 17, 2026 20:36
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.

3 participants