Open dummdidumm opened 6 months ago
ideally in a less on-the-fly way compared to before
Yes, that's a good way to put it. :) For reference, Kitbook's scaled down version of what Svelte DevTools had to do on-the-fly is here and then I added this to move elements up into a parent component if they come from a node_modules component. The incentive for moving elements up the chain is that I had some situations where a local component has no dom elements of its own but only node_modules components with dom elements. I still have no option to enable targeting components which have no local elements as only the elements carry the file location reference and not components. There's no need to try to read through that code, just wanted to say it'd be a real boost to have something simpler made available.
Here's my list of what's needed for building a component tree w/ each local component knowing which DOM elements it owns.
[ ] on component mount emit an event like SvelteRegisterComponent
that includes:
file location
- important for being able to jump to the source code for those components without DOM elements. They can still easily be selected with a simple tree viewer:
props
capture_state
function (and optionally capture_props_state
would be nice but it can be calculated on-the-fly)set_state
function SvelteRegisterBlock
's block
to match to the correct component's component.$$.fragment
and doing some wizardy for the pending
await block.)parentComponent
- the unique component identifier for a component's parent component to be able to build a treeSvelteUnregisterComponent
Button.svelte
into +page.svelte
and I hover over the button, I want to jump to +page.svelte
. With some backflips, I'm currently doing this now, but if +page.svelte
has no elements of it's own, its source file location information is not currently available.SvelteDOMInsert
and SvelteDOMRemove
events with the elements which will include that metadata. If the unique component identifier is not practical to keep in the DOM then just including it in these events is sufficient.Note that the above list means all mounted components from node_modules will have 0 children elements registered to them. That's fine, but please still emit the SvelteRegisterComponent
event for them so we can capture and set state if desired.
I don't need the SvelteRegisterBlock
anymore if we have the above list.
What I've written down will eliminate all of my code's backflips and will require just listening to the appropriate events. However, you may be envisioning something more low-level like having the SvelteKit plugin maintain current component-elements tree state which libraries can then just request from the dev server and receive updates from via server broadcasted events. I'm good with whatever approach is taken.
Describe the problem
Svelte 4 emits some events in dev mode around elements being inserted etc and provides location info on the elements that map back to the original code.
Svelte 5 currently doesn't have any of it. To support devtools et al, it needs to be added back, ideally in a less on-the-fly way compared to before.
Describe the proposed solution
No good idea yet - first we need to collect requirements from tooling:
Importance
nice to have