Skip to content

Music Lab: hot reload fix - #74871

Open
breville wants to merge 2 commits into
stagingfrom
music-hot-reload-fix
Open

Music Lab: hot reload fix#74871
breville wants to merge 2 commits into
stagingfrom
music-hot-reload-fix

Conversation

@breville

@breville breville commented Aug 25, 2026

Copy link
Copy Markdown
Member

[written by Claude]

Music Lab could lose work in development: a hot update remounts MusicView, which loaded the page's original sources again and saved them over the project. The mount now loads the project's current sources instead.

What happened

MusicView is a class component, which React Fast Refresh remounts rather than preserves. Every development rebuild that reached it ran componentDidMount again, and the mount called onLevelLoad with initialSources — the sources the page loaded with. loadCode saves whatever it loads, so the remount immediately wrote those stale sources over everything done since the page opened. It looked like "my last few changes vanished after a rebuild". Production never hot-reloads, so students were never exposed; this is a developer-experience fix.

The fix

  • ProjectManager gains getCurrentSources(): the sources waiting to be saved, else the last saved or loaded ones.
  • MusicView's mount loads those, falling back to initialSources only when there is no project manager. In production they are the same sources, since load stores what it returns, so nothing changes there.

Sprite Lab in Lab2 had a sibling of this bug the same afternoon (a seed effect re-run by Fast Refresh, then autosaved); its fix is in #74845.

Testing

  • New ProjectManager unit test: the current sources are the loaded ones before any save, the saved ones after, and the queued ones while a save waits for its interval. The existing 37 pass. Typecheck and lint clean.
  • Browser, on the dev server: added a block to a project and let it save, then edited MusicView.jsx to trigger a hot update. With the fix the component remounted and the block stayed in the workspace and in the stored sources. With staging's MusicView.jsx swapped in, the same hot update reverted the workspace to the when-run block alone and the stored sources lost the block within the save interval.

MusicView is a class component, which React Fast Refresh remounts rather
than preserves, so every development rebuild that reaches it ran
componentDidMount again with the sources the page loaded with. loadCode
saves what it loads, so the remount wrote those stale sources over
whatever had been done since the page opened.

The mount now asks the project manager for the sources it holds — pending
save, else last saved or loaded — and falls back to initialSources only
when there is no manager. ProjectManager gains getCurrentSources for that;
in production the two are the same object, since load stores what it
returns.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@breville breville changed the title Music Lab: a remount loads the project's current sources, not the page's Music Lab: hot reload fix Aug 25, 2026
@breville breville added the AI generated This PR has been substantially generated using AI. label Aug 25, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI generated This PR has been substantially generated using AI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant