sveltejs / svelte

web development for the rest of us
https://svelte.dev
MIT License
79.96k stars 4.25k forks source link

Svelte 5: Provide metadata/events needed for devtools et al #11389

Open dummdidumm opened 6 months ago

dummdidumm commented 6 months ago

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

jacob-8 commented 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.

Requested

Here's my list of what's needed for building a component tree w/ each local component knowing which DOM elements it owns.

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.