diff --git a/src/js/program-mixin.js b/src/js/program-mixin.js index a9f1a0d..e8c2aad 100644 --- a/src/js/program-mixin.js +++ b/src/js/program-mixin.js @@ -580,7 +580,18 @@ module.exports = { // right file. if (file_name != this.state.selected) { this.state.selected = file_name; - await api.get(`file/${encodeURIComponent(file_name)}`); + // GET /api/file/ returns gcode text (not JSON), so use + // fetch directly. The server's FileHandler.get sets + // state.selected as a side effect; we await the response + // before starting so mach.start() reads the right file. + const resp = await fetch( + `/api/file/${encodeURIComponent(file_name)}`, + { cache: "no-cache" } + ); + if (!resp.ok) { + throw new Error(`file fetch failed: ${resp.status}`); + } + await resp.text(); } this.load(); if (this.state.macros[id].alert == true) {