sites icon indicating copy to clipboard operation
sites copied to clipboard

(life cycle: onDestroy) tutorial does not clear intervals when recompiling.

Open nasheomirro opened this issue 4 years ago • 2 comments

Description typing out setInterval function calls will result in the console being flooded with error messages, largely because there is no milliseconds passed yet and the variables being used still haven't been fully typed. The setInterval function call it self is valid so the compiler will compile and re render the result.

Logs Error: s is not defined Error: se is not defined Error: sec is not defined Error: second is not defined Error sec is not defined ...

To Reproduce On the editor, type a setInterval call slowly and must have an ending parentheses i.e setInterval(). NOTE: type the setInterval call inside the App.svelte script tag. I'm sure this is also the case with other tutorials using setInterval() inside the script tag.

You will notice that if it compiles while you haven't finished typing it all out, the console is being flooded. The problem will persist even when recompiling the code.

Expected behavior The console shouldn't be printing any more errors when the answer is working.

Severity VERY MINOR - just a problem with logging errors in the tutorial, people will get confused if they encounter this though.

nasheomirro avatar Mar 20 '21 17:03 nasheomirro

Transferring this to the REPL repository, although I'm not sure what we could reasonably do to resolve this. Maybe monkeypatch/inject our own copies of setTimeout/setInterval that internally note somewhere the timeout/interval id so that we can manually destroy them when recompiling?

Conduitry avatar Mar 24 '21 00:03 Conduitry

https://github.com/sveltejs/svelte/issues/7196 brought up the same sort of issue with requestAnimationFrame, and I'm not sure how to best handle that, either.

Conduitry avatar Jan 27 '22 23:01 Conduitry