You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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(constthingofthings){
...
}
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:
for (|) {
for (let |) {
for (let i = |) {
for (let i = 0; |) {
for (let i = 0; i < |) {
for (let i = 0; i < things.|) {
for (let i = 0; i < things.length|) {
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:
Add a toggle in the UI to disable auto-run – but not everyone will think about this before it's too late.
Solve the halting problem to decide if the code is safe to run – this might have applications outside of the Svelte Playground.
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)
The text was updated successfully, but these errors were encountered:
Today I was playing with nested
$effect
s in the playground to understand them better. At some point, I needed to write afor
loop: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:for (|) {
for (let |) {
for (let i = |) {
for (let i = 0; |) {
for (let i = 0; i < |) {
for (let i = 0; i < things.|) {
for (let i = 0; i < things.length|) {
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 unfinishedfor
loop! And without the increment, it wasn't gonna stop any time soon.I see three solutions to this problem:
The text was updated successfully, but these errors were encountered: