Repository navigation
Description
Deleting a saved instrument leaves its files in the playground editor and preview, while the instrument selector switches to Unilingual Form. removeInstrument sets selectedInstrument back to the default template but leaves files, indexFilename, openFilenames and selectedFilename alone, unlike setSelectedInstrument and resetInstruments. After Delete Instrument, the header says Unilingual Form and a notification says the instrument was deleted, but its code is still on screen under the template's name. Download Archive then exports the deleted code as Unilingual-Form.zip, and Create New Instrument clones it.
Where
apps/playground/src/store/slices/instrument.slice.ts:19-24:
removeInstrument: (id) => {
set((state) => {
state.instruments = state.instruments.filter((item) => item.id !== id);
state.selectedInstrument = defaultSelectedInstrument;
});
},Reproduce
- Click Create New Instrument, name it
Mineand save, then changeindex.tsand click Save. - Open the actions menu (the vertical ellipsis), choose Delete Instrument and confirm.
Actual: the selector reads Unilingual Form, but the editor and preview still show Mine's code.
Expected: the editor and preview show the Unilingual Form template.
A node test of the store gives the same result: after setSelectedInstrument(saved.id) and then removeInstrument(saved.id), selectedInstrument.label is Unilingual Form and files still holds the removed instrument's contents.
Tests
apps/playground/src/store/slices/__tests__/instrument.slice.test.ts: it('should load the default instrument's files when the selected instrument is removed, so the editor never shows a deleted instrument').
E2E in testing/src/specs/playground.spec.ts: create and save an instrument with distinctive content, delete it from the actions menu, and assert that the editor shows the template's content.
Suggested fix
When the removed id is the selected instrument, have removeInstrument apply the same editor reset that resetInstruments does (files, index filename, open tabs and selection from defaultSelectedInstrument).
Activity
fix(playground): load the default template after deleting an instrument