Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playground auto-run can hang the page when running unfinished code #1074

Open
nasso opened this issue Dec 28, 2024 · 0 comments
Open

Playground auto-run can hang the page when running unfinished code #1074

nasso opened this issue Dec 28, 2024 · 0 comments

Comments

@nasso
Copy link

nasso commented Dec 28, 2024

Today I was playing with nested $effects in the playground to understand them better. At some point, I needed to write a for loop:

for (const thing of things) {
  ...
}

Amazing! Actually, not amazing. Turns out I needed the index. A clever guy would have reached for Array.prototype.entries(), but I'm not a clever guy, so I immediately went for the good old counter. This is roughly how I updated my code:

  1. for (|) {
  2. for (let |) {
  3. for (let i = |) {
  4. for (let i = 0; |) {
  5. for (let i = 0; i < |) {
  6. for (let i = 0; i < things.|) {
  7. for (let i = 0; i < things.length|) {
  8. for (let i = 0; i < things.length; i|) {

At this point, I wasn't done typing. I only had ++ left. But I couldn't type! In fact, I couldn't do anything anymore on the entire page. And then it hit me. It ran my unfinished for loop! And without the increment, it wasn't gonna stop any time soon.

I see three solutions to this problem:

  1. Add a toggle in the UI to disable auto-run – but not everyone will think about this before it's too late.
  2. Solve the halting problem to decide if the code is safe to run – this might have applications outside of the Svelte Playground.
  3. Stop the script after some time – will break scripts doing a lot of things in a blocking manner on the main thread (but maybe they deserve it)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant