vite-plugin-svelte icon indicating copy to clipboard operation
vite-plugin-svelte copied to clipboard

separate es modules for `<script context="module">` and `<script>` during dev / hmr

Open dominikg opened this issue 2 years ago • 2 comments

Describe the problem

Current implementation in svelte-hmr self-accepts updates to Component.svelte, which can cause broken references for exports of context=module scripts. see #134

Describe the proposed solution

Instead of returning 1 es-module for Component.svelte js, return a facade wrapping 2 virtual modules, allowing for separate hmr updates and properly propagating updates of context=module

Alternatives considered

Use acceptNamedExports: false option of svelte-hmr, letting updates bubble and live with extra reloads

Importance

would make my life easier

dominikg avatar Aug 07 '21 10:08 dominikg

This is a draft to collect information and lay out a plan what has to be done and document experiments around it. If you have ideas or opinions on this topic, please share.

dominikg avatar Aug 07 '21 10:08 dominikg

Note: This is also discussed in a discord thread.

bluwy avatar Aug 08 '21 16:08 bluwy

since the addition of partial accept to vite and svelte-hmr 0.15 + vite-plugin-svelte 1.0.6 supporting it, the change described here would add little to no additional benefit and would add significant complexity.

We might revisit it later if other needs present themselves but for now the current solution does allow for granular updates even with context=module.

dominikg avatar Oct 02 '22 08:10 dominikg