DEV Community

Discussion on: How I made a live code editor with Vanilla Javascript?

Collapse
 
loucyx profile image
Lou Cyx

You might want to use Workers or something that runs your code in a different process safely, because if I'm reading your code correctly, if you write something like while (1){} in the JS editor, you freeze the entire app.

Collapse
 
mfatihgul profile image
Muhammet Fatih Gul

I'll learn about it soon and improve myself. Thank you so much for your advice

Collapse
 
hepisec profile image
hepisec

It shouldn't matter because the code is sent to the client and is not evalled. So the client would freeze itself if it enters while (1) {}

Collapse
 
loucyx profile image
Lou Cyx

.... it still matters. If you're writing while(value) { and said value starts as a truthy and you were planning to set it to falsy inside that while, you'll never be able to do that because the editor will freeze before that. You write infinite loops all the time, you just write the logic to stop them after, if an editor renders as soon as you write, it will freeze. It should ideally show an error as editors like CodeSandbox, CodePen or StackBlitz do.