Closed davidlueder closed 2 years ago
After inspecting your example, it seems that this reliably happens when unmounting and island component that has a fragment template (several sibling nodes at the root), failing at removeFragment
.
This is likely to be a Vue bug which is very rare in practice, since it requires:
Most Vue apps are never unmounted, and typically have a single root node, which is why I say it's rare in practice.
If you can investigate and provide a small replication for Vue that doesn't depend on iles, it's likely that the Vue core team would fix it.
In the meantime, I'd suggest using a single root node in Vue islands, as in:
<template>
<div>
<p>This is the component</p>
<span ref="scriptAddition"></span>
</div>
</template>
Thank you, using a single root node is of course absolutely no problem.
I have tried to reproduce this just using vue & vite, but maybe i did not understand your explanation completely: https://stackblitz.com/edit/vitejs-vite-s4qyl1
Until now it seems like unmounting a fragmented root template doesn't result in an error
Hi David, thanks for looking into it.
After doing some experiments, I also could not replicate the problem outside of HMR, as it seems to be specific to how HMR reloads the component by unmounting and remounting. The conflict occurs because for Vue islands the component is rendered first before the hydration script kicks in. This double-rendering seems to break the assumptions of unmount
, which is heavily optimized to avoid rework, and expects the sibling elements to be present when clearing fragments.
I think a reasonable workaround will be not to pre-render Vue islands in development (similar to how it works for other framework islands), and let the inline script do the hydration + rendering on its own. This would also avoid confusing behavior such as #110.
I'll see if I can implement this while wrapping up a new CSS splitting feature once Vite 2.9 is released.
iles
andvite
.Description ๐
Changing anything within a components setup script, that was used in a page with the
client:load
attribute results in an error in the browser console.The error contains
This is likely a Vue internals bug.
but when removing theclient:load
attribute from the component tag everything works fine. This is why i think that might be an issue in iles.Reproduction ๐
Logs ๐
Screenshots ๐ท