solidjs / solid-refresh

MIT License
86 stars 18 forks source link

Should async `onCleanup` be expected to have been completed before HMR respawns a component? #69

Closed Enteleform closed 4 months ago

Enteleform commented 4 months ago

I ran into an issue with a third-party library that has a registration/unregistration process which is causing errors during HMR due to an unexpected order of events.

To prevent this error, the following event order would be required:

But this is what's actually occurring:

Here's a minimal repro: https://stackblitz.com/edit/solid-vite-lynwpq?file=src%2Findex.tsx

lxsmnsyc commented 4 months ago

it's expected. HMR is usually fast enough to reload before that 1s timeout can even run.

Enteleform commented 4 months ago

Would it be possible to add an option for solid-refresh that waits for onCleanup to finish before respawning components?

And are there any recommended workarounds/patterns for avoiding this issue?

lxsmnsyc commented 4 months ago

No, because even Solid doesn't manage async lifecycle callbacks. You'll have to manage this on your own.

Enteleform commented 4 months ago

Gotcha, thanks for the info 👍