Skip to content

Reset the engine after a template builds, not before - #59

Merged
zntznt merged 1 commit into
mainfrom
claude/ui-ux-run-4qmy5r
Aug 27, 2026
Merged

zntznt merged 1 commit into
mainfrom
claude/ui-ux-run-4qmy5r

Conversation

@zntznt

@zntznt zntznt commented Aug 27, 2026

Copy link
Copy Markdown
Owner

The bug

Loading a starter template left the step-0 history entry empty, so every chart opened on a hole. Run the Predator & Prey template straight after loading it and the Rabbits series came back:

[null, 89, 94, 93, 87, 76]

The starting population of 80 is nowhere in it and the curve begins at step 1.

Cause

Purely ordering. Both loaders called _clearAll(), which resets the engine, and only then ran the template's load(). reset() ends by recording a step-0 baseline of the current nodes, so it captured an empty diagram; the nodes arrived afterwards and nothing reset again.

The saved-diagram loader already had this right: clear, load, then reset.

Measured before and after, same template:

before   snapEntries: 0   for 3 nodes   series[0] = null
after    snapEntries: 3   for 3 nodes   series[0] = 80

Why it matters beyond the chart

That baseline is also what scrub shows at step 0, and what spike attribution reads as the "from" value for the first real step. All three were working from nothing.

The fix

Reset once the template has built its nodes.

Both entry points (Library template, welcome demo) carried their own copy of the same nine lines, which is how one bug came to live in two places. They now share _installTemplate, and each keeps only its own last step: the Library hides its modal, the welcome demo re-renders the properties panel.

Files

  • js/app-library.js — _installTemplate helper with the corrected reset order; _loadTemplate reduced to the guard plus its modal
  • js/app.js — _loadDemo reuses the helper
  • test/smoke.js — regression test

UI layer only. No change to model.js or engine.js, and no serialized fields added.

Testing

  • node test/run.js → 235 passed, 0 failed (unchanged; UI-layer change)
  • npm run smoke → SMOKE PASSED, no console or page errors
  • The new smoke test drives both entry points, asserting every node appears in the step-0 baseline and that a stepped series has no hole at index 0. Without the fix it reports step0Entries: 0, covered: false, firstIsNull: true for both paths.

The test calls _loadTemplate and _loadDemo rather than the new shared helper deliberately: an earlier version called _installTemplate, which meant that without the fix it threw a ReferenceError instead of detecting the bug, so it would have "failed" for the wrong reason. Driving the real entry points measures behaviour rather than the presence of a function.

Worth noting the existing P3 CSV: history export (header + step-0 baseline + 4 steps) test passes both with and without this change: its diagram is not template-loaded, which corroborates that the step-0 baseline works normally and this was specific to the template path.


Generated by Claude Code

Loading a starter template left the step-0 history entry empty, so every
chart opened on a hole. Run the Predator & Prey template straight after
loading it and the Rabbits series came back

  [null, 89, 94, 93, 87, 76]

with the starting population of 80 nowhere in it and the curve beginning
at step 1.

The order was the whole of it. Both loaders called _clearAll, which resets
the engine, and only then ran the template's load(). reset() ends by
recording a step-0 baseline of the current nodes, so it captured an empty
diagram; the nodes arrived afterwards and nothing reset again. The
saved-diagram loader already had this right, clearing, loading, then
resetting.

Reset now happens once the template has built its nodes. Beyond the
missing first chart point, that baseline is what scrub shows at step 0 and
what spike attribution reads as the "from" value for the first real step,
so all three were working from nothing.

Both entry points had their own copy of the same nine lines, which is how
one bug came to live in two places, so they now share _installTemplate and
each keeps only its own last step: the Library hides its modal, the
welcome demo re-renders the properties panel.

Covered by a smoke test driving both entry points, asserting every node
appears in the step-0 baseline and that a stepped series has no hole at
index 0. Without the fix it reports step0Entries 0 and firstIsNull true
for both. It calls _loadTemplate and _loadDemo rather than the new shared
helper, so it measures the behaviour and not the presence of a function.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SH7ouoNymubArm7VEgALHg
@zntznt
zntznt merged commit c82098b into main Aug 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants