fix: normalize viewport shape on FlowState.load#61
Merged
Conversation
Legacy/hand-written .drawd files may persist viewport as `{x,y,scale}` or
omit pan/zoom entirely. The previous `data.viewport || default` only caught
the missing-key branch, so files with the wrong shape passed through and
crashed the next autosave with "Cannot read properties of undefined (reading
'x')" inside buildPayload.
Add a normalizer at the read boundary that accepts canonical `{pan,zoom}`,
legacy `{x,y,scale}`, partial, and missing inputs and always returns the
canonical shape — keeping buildPayload as the single source of truth for the
output shape. Add 5 regression tests including a load → save round-trip that
rewrites a legacy-shape file in canonical form.
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.
Summary
FlowState.loadthat accepts the canonical{pan,zoom}shape, the legacy{x,y,scale}shape, partial inputs, and missing-entirely inputs — always returning the canonical shape.buildPayloadas the single source of truth for the persisted shape; fixes the immediateCannot read properties of undefined (reading 'x')crash on autosave after loading a legacy- or hand-written.drawdfile.state.test.js, including a load → save round-trip that asserts the file is rewritten in canonical form.Why
Discovered while smoke-testing today's MCP merges (#55, #57, #58, #59, #60). Bootstrapping a new
.drawdby hand withviewport:{x,y,scale}opened cleanly but crashed the next mutation. The previousdata.viewport || defaultonly guarded the missing-key branch, not wrong-shape inputs — so any drift in the persisted viewport shape would silently load and then explode on the next save.The existing 28
state.test.jscases never exercisedload()(they all went throughcreateNew()), which is why the gap survived. The new tests cover load directly.Test plan
npm test— 1049 passed (1044 → 1049, +5 new, zero regressions)npm run buildfromdrawd-private/— lint + Vite build cleanmain, confirmed gone on this branch