sveltejs / sites

Monorepo for the sites in the Svelte ecosystem
https://svelte.dev
MIT License
286 stars 123 forks source link

(fix) attribute deletion causes repl to freeze #512

Closed paoloricciuti closed 1 year ago

paoloricciuti commented 1 year ago

closes #496

This issue is due to the fact that the array of the diagnostics get's out of sync with the actual code for a brief moment. This usually it's not a huge problem because it get's recomputed moments later but it can be a problem when the error falls outside of the max length of source code.

To avoid this issue i've added a bundling promise inside the context that get's reassigned whenever a bundling process starts and resolved immediately after the new bundle has been assigned to the store. The diagnostic has also been transformed from an array that get's recalculated dynamically to an async function that awaits the bundling process. Finally instead of simply passing the diagnostics to neocodemirror we create a linter extension passing the aforementioned async function. Codemirror will call and await this function at each modification.

A couple of points:

  1. This means the diagnostics feel a bit more slow because it has to wait for the bundling to finish, however this is more correct since the diagnostics immediately reflect the actual source code.
  2. This could also be "fixed" upstream in @PuruVJ @neocodemirror library, right now does work as intended but it uses setDiagnostics and it might be beneficial to use the linter extension instead to allow for async diagnostic calculation. So if @PuruVJ prefer to first upgrade @neocodemirror i can update this pr whenever he push a new release there.
vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hn ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 30, 2023 5:39pm
paoloricciuti commented 1 year ago

I'll try to close and reopen to trigger the deploy on vercel

paoloricciuti commented 1 year ago

Ok apparently it doesn't work just by this...I'll try to close it and open a new one