Repository navigation
fix(gui): prevent stack-overflow crash when emptying pattern/skip fields - #164
Merged
Merged
Conversation
…mptied Emptying the Pattern Number or Skip Index input yields NaN. The editor re-validates all helical fields, so the sibling field's coprime check called gcd() with the NaN value. gcd is recursive Euclid; gcd(x, NaN) never terminates (Math.abs(NaN) is NaN, NaN === 0 is false, NaN % NaN is NaN), so it blew the call stack and tripped the error boundary with 'RangeError: Maximum call stack size exceeded'. Guard validateCoprime to no-op unless both pattern and skip are integers (Number.isInteger also rejects NaN, Infinity, and non-integers). The mid-edit field still surfaces its own range error, so validation feedback is unchanged. Adds regression tests for NaN and non-integer siblings.
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.
Symptom
A user hit "Something went wrong — RangeError: Maximum call stack size exceeded" (React error boundary) right after backspacing the Skip Index (or Pattern Number) value in a helical layer editor — no Enter needed. The stack was a single function recursing into
Math.abs.Root cause
Emptying a numeric input produces
NaN. The editor'suseEffectre-validates every helical field, so validating the sibling field runs the cross-field coprime check:gcdis recursive Euclid, andgcd(x, NaN)never terminates —Math.abs(NaN)isNaN,NaN === 0is false, andNaN % NaNisNaN— so it recurses until the stack overflows.Fix
Guard
validateCoprimeto no-op unless bothpatternandskipare integers (Number.isIntegeralso rejectsNaN,Infinity, and non-integers). Coprimality is only defined for two positive integers anyway, and the field that's mid-edit still surfaces its own "must be a valid number" range error — so user-facing validation feedback is unchanged; only the crash is gone.Tests
Added regression cases to
helicalValidation.test.ts:pattern_numberwithskip_index = NaNdoesn't throw (and reports no spurious coprime error)pattern_number = NaN)2.5) sibling doesn't throwvitest24 passed (was 20),tsc --noEmitclean.