Reset the engine after a template builds, not before - #59
Merged
Merged
Conversation
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
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 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:
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'sload().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:
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—_installTemplatehelper with the corrected reset order;_loadTemplatereduced to the guard plus its modaljs/app.js—_loadDemoreuses the helpertest/smoke.js— regression testUI layer only. No change to
model.jsorengine.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 errorsstep0Entries: 0, covered: false, firstIsNull: truefor both paths.The test calls
_loadTemplateand_loadDemorather 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