Repository navigation
feat: include the component instance in the dev __svelte_meta - #19286
Conversation
`__svelte_meta` tells tools which file and line rendered an element, but
not which component instance did. When the same component is rendered many
times (a button in a list, a row in an `{#each}`), a tool that starts from a
DOM element (an element picker, an inspector) cannot tell the instances
apart, so it can't jump to the right one in a component tree or show that
instance's state.
`component` is the component context the element was rendered in. It is
the context that was already current when the element was created, so no
new tracking is added: inside a snippet it is the component rendering the
snippet, matching the render-tree `parent` stack.
Cost: one more property on an object that dev mode already creates per
element; nothing in production, where `__svelte_meta` isn't assigned.
Mounting 20 000 elements in dev (jsdom, median of 35 runs, 3 runs each)
took 419-433 ms with the change and 417-437 ms without it.
|
Install the latest version of pnpm add https://pkg.svelte.dev/svelte/c/2c1c788232c825cf735282319e1e500b6db7aa50Open in |
🦋 Changeset detectedLatest commit: 2c1c788 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
`__svelte_meta` tells tools which file and line rendered an element, but
not which component instance did. When the same component is rendered many
times (a button in a list, a row in an `{#each}`), a tool that starts from a
DOM element (an element picker, an inspector) cannot tell the instances
apart, so it can't jump to the right one in a component tree or show that
instance's state.
`component` is the component context the element was rendered in. It is
the context that was already current when the element was created, so no
new tracking is added: inside a snippet it is the component rendering the
snippet, matching the render-tree `parent` stack.
Cost: one more property on an object that dev mode already creates per
element; nothing in production, where `__svelte_meta` isn't assigned.
Mounting 20 000 elements in dev (jsdom, median of 35 runs, 3 runs each)
took 419-433 ms with the change and 417-437 ms without it.
From #19286, taken into this branch so devtools can resolve
an element to its component instance before that PR is merged.
…er-module skip - The kit3 compat profile installs outside the workspace, so it got Svelte 5.57.3 from npm, which has no `svelte/internal/devtools`; its dev server never started. It now links the branch build too. - The pinned emit-dev-events commit includes sveltejs/svelte#19286 (`__svelte_meta.component`), which the element picker will use. - plugin.ts lost branch coverage below its 95% threshold when the componentTracking cases went away: the tracking transform's skip of a server-compiled module is tested directly.
The Reactivity and Components panels make you find the component first, which is hard in a large app; users start from what they see on the page. The Svelte Inspector fork (packages/inspector) is now shipped with the plugin and linked to the DevTools: in inspector mode a click selects the element's component instance in the Components panel (tree revealed, details open), and Alt/⌥+click opens the source in the editor as before. The hover label shows the instance and both actions. A "Pick element" button in the Components panel turns the inspector on in the app page. - The instance comes from `__svelte_meta.component` (sveltejs/svelte#19286), resolved to the nearest tracked component. - The pick goes page -> dev server -> every DevTools UI (two tabs, or the Vite DevTools dock, which is opened on a pick). The server keeps the last pick for 10 s, so a dock panel loaded by that pick still gets it. - Changes to the forked files are marked and listed in packages/inspector/README.md; without the DevTools link the fork behaves as upstream. `svelteDevtools({ inspector })` sets its options or turns it off. - Library components are recognised also when their filename is relative to the project (`node_modules/...`).
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.
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
|
Thank you for your review! |
…stom-element slots still receive metadata without `component`, preventing element-based tooling from identifying their rendering instance. This commit fixes the issue reported at packages/svelte/src/internal/client/dev/elements.js:30 ### Missing metadata writers The merged base also assigns `__svelte_meta` in `dom/blocks/html.js`, `dom/blocks/snippet.js`, and `dom/blocks/slot.js`. Those assignments still contain only `parent` and `loc`. Since `assign_locations` skips elements that already have metadata, this new assignment never fills in their `component` field. For example, the `<b>` emitted by `svelte-meta-html-snippet`, both `<section>` roots in `svelte-meta-raw-snippet`, and the native `<slot>` elements in `svelte-meta-native-slot` all have an undefined `__svelte_meta.component`, while their enclosing `<output>` has a valid context. An inspector selecting these roots cannot use the new field to identify the rendering instance. ### Fix and validation The suggested patch adds the current component context to all three remaining metadata writers and adds ownership assertions to their existing tests. Those assertions failed in all five applicable DOM/hydration variants before the runtime fix; all 29 focused `svelte-meta` tests passed afterward. The full suite was not run. Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com> Co-authored-by: dummdidumm <sholthausen@web.de>
__svelte_metatells tools which file and line rendered an element, but not which component instance did. When the same component is rendered many times (a button in a list, a row in an{#each}), a tool that starts from a DOM element (an element picker, an inspector) cannot tell the instances apart, so it can't jump to the right instance in a component tree or show that instance's state.This adds
componentto the dev__svelte_meta: the component context the element was rendered in.parentstack (loc.filestill points at the file that declared the snippet).<svelte:element>.Performance
__svelte_metais only assigned in dev).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