Repository navigation
fix: assign dev element locations at template creation on the client - #19291
Conversation
#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
|
Install the latest version of pnpm add https://pkg.svelte.dev/svelte/c/e4709606645049dcef2d6c60a3e2db22b26e0974Open in |
|
There was a problem hiding this comment.
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.
Follow-up to #19287.
#19287 moved
$.add_locationsto 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_metaand can be skipped.On the client, though,
assign_locationsdoesn'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_metatakes 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>'spendingsnippet.createRawSnippetonly sets__svelte_metawhendev_stackisn'tnull, and it isnullthere:__svelte_metaafter components properly #19287main<section>(raw snippet)main.svelte:13:1(the<p>'s location)<p>main.svelte:13:1a 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:
Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.packages/svelte/src, add a changeset (npx changeset).Tests and linting
pnpm testand lint the project withpnpm lint🤖 Generated with Claude Code
https://claude.ai/code/session_01MNFNHpae1SEriX7anW4ChC