Fix: infinite loop crashes and autosave loss #3891#3896
Open
Nixxx19 wants to merge 13 commits intoprocessing:developfrom
Open
Fix: infinite loop crashes and autosave loss #3891#3896Nixxx19 wants to merge 13 commits intoprocessing:developfrom
Nixxx19 wants to merge 13 commits intoprocessing:developfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3891
Summary
Fixes browser crashes and data loss from infinite loops. Adds localStorage crash recovery, improves loop detection (including multiple loops on same line), and provides clearer error messages.
Before: Many infinite loops caused browser hang/freeze as all loops executed simultaneously.
After: Execution stops immediately when multiple loops are detected (
hitCount > 1), preventing hang even with 66 infinite loops. See screenshot below.Changes
1. localStorage Backup System (Crash Recovery)
Saves code to localStorage on every change, restores on project load if backup is newer than server save. Prevents data loss when browser crashes from infinite loops.
updatedAt2. Always Apply loopProtect
Previously skipped when JSHINT found errors, leaving users vulnerable while typing incomplete code. Now always applies
loopProtecteven if parsing fails.loopProtectafter decommentloopProtecton original code if needed// noprotectopt-out3. Detect Multiple Loops on Same Line
Consecutive loops like
for(){}for(){}bypass protection. Regex detects and adds semicolons between them so each loop is wrapped individually.((?:for|while)\s*\([^)]*\)\s*\{[^}]*\})((?:for|while)\s*\([^)]*\)\s*\{[^}]*\})for(){}for(){}→for(){}; for(){}4. Improved Loop Detection & Messages
Simplified messages, immediate stop for multiple loops.
Logic:
hitCountandfirstLine(reset after 1s)Why 66 loops don't hang:
hitCount > 1), not after detecting all loops5. Auto-refresh Fix
Removed
isPlayingcheck so auto-refresh works regardless of play state, preventing stale saves.I have verified that this pull request:
npm run lint)npm run test)npm run typecheck)developbranch.Fixes #3891