lustre-labs / dev-tools

Lustre's CLI and development tooling: zero-config dev server, bundling, and scaffolding.
47 stars 15 forks source link

Infinite build & reload loop when saving FFI file #71

Open mdarse opened 1 month ago

mdarse commented 1 month ago

When using the live reload feature (gleam run -m lustre/dev start), each time I save an FFI (.mjs) file, the process fall in an infinite loop that triggers infinite reloads in the browser.

I run macOS 14.6.1, and could reproduce the issue with multiple editors including Zed & vi.

After quite a bit of digging around the fs module I found that after an initial (and correct) change detected on the saved FFI file (with events [Inodemetamod, Modified]), I get another change on this same file with the same events but a change on every other FFI files with the [] events. Then this loops again.

I’ve found a workaround by commenting out these two lines. https://github.com/lustre-labs/dev-tools/blob/10452a048fba334659216a38d48ddd4cbe2e6758/src/lustre_dev_tools/cli/build.gleam#L76-L77

So the issue seems related to the gleam compiler exporting the package information (or an interaction between this and the regular build process).

Sometime the build loop stops after some time, most of the time not. So we may have a race somewhere.

hayleigh-dot-dev commented 1 month ago

Oh how odd, I would think neither of those two things would trigger any fs events at all 🤔 I think @giacomocavalieri may have mentioned sometimes getting stuck in a similar loop but it's not something I've managed to run into yet (also Mac, also Zed).

I'll try to investigate, thank you for digging into it already!