fix: crash when editing a field + make app null-safe (strict TS) - #7
Merged
Conversation
…l-safety Crash: "Cannot read properties of undefined (reading 'label')" in a template's renderRow when you delete text from a field. FramedDoc caches the paginated pages in state (updated by an effect after render); on the next render the new, shorter data was laid out against the OLD pages, whose row indices no longer existed -> sections[s].rows[r] was undefined. Fix (two layers): - Tag cached pages with the data signature they were built from and only use them when it still matches; otherwise lay out the current units directly. - Make nodeFor null-safe: return null for any missing section/row instead of dereferencing undefined. Null-safety hardening (so the compiler catches this class of bug): - tsconfig: enable noUncheckedIndexedAccess + noImplicitOverride. - paginate.ts / pdf.ts: guard array index access in loops. - templates registry + headerPresets: typed as non-empty tuples so [0] is always defined. - BiodataForm: coerce optional accordion open-state to boolean. tsc (strict) clean, lint clean, 37 tests pass, build green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
The crash
You reported the app crashing when deleting/clearing the name. The error (from your screenshot):
Root cause
FramedDoccaches the paginatedpagesin React state, updated by an effect that runs after render. When you edit a field, the component re-renders with the new, shorter data but the oldpages, which still reference row indices that no longer exist →sections[s].rows[r]isundefined→row.labelthrows. Timing-sensitive, which is why it only reproduces with real layout measurement.Fix (two independent layers)
nodeForis null-safe — returnsnullfor any missing section/row instead of dereferencingundefined.Null-safety hardening (your "make it null-safe + fully typed" ask)
Enabled
noUncheckedIndexedAccess(+noImplicitOverride) — every array/object index is nowT | undefined, so the compiler forces guards. This flag would have caught the crash at compile time. Fixed the 15 spots it surfaced:paginate.ts/pdf.ts: guarded index access in loops.headerPresets: typed as non-empty tuples so[0]is always defined.BiodataForm: coerce optional accordion state to boolean.Verification
tsc --noEmit(strict + noUncheckedIndexedAccess): 0 errorsnpm run lintclean ·npm test37/37 ·next buildgreen🤖 Generated with Claude Code