pmndrs / directed

A flexible, minimal scheduler written in TypeScript
MIT License
25 stars 1 forks source link

Working with HMR #12

Closed krispya closed 3 months ago

krispya commented 3 months ago

Using the scheduler with HMR is a bit problematic. So far I have two obvious issues:

  1. Duplicates of the same runnable get scheduled if the function regenerates.
  2. If it doesn't regenerate it errors out since the same system can't be added twice.

It looks like a solution will involve implementing our own HMR dispose functions: https://vitejs.dev/guide/api-hmr#hot-dispose-cb

krispya commented 3 months ago

I investigated this a little more and found that the dispose cb doesn't work how I expect it to. The best recommendation is to just move the schedule and the adds to its own module so that if it gets HMRed it gets rebuilt completely. A React hook should help make this simple since it supports cleanup functions.