fix(flash): block web flashing for MicroPython boards

compiledProgram holds the 'micropython-loaded' sentinel in MicroPython
mode, not a flash image — atob() blew up with an encoding DOMException
before the port chooser even opened. The menu item now disables with an
explanatory tooltip and the modal shows the limitation instead of the
Connect button.
This commit is contained in:
David Montero Crespo 2026-08-11 22:37:15 +02:00
parent 8694a53d44
commit 820a0fa024
2 changed files with 22 additions and 6 deletions

View File

@ -404,7 +404,10 @@ interface WebReadyProps {
}
const WebReadyView = ({ board, onFlash }: WebReadyProps) => {
const hasCompiled = !!board.compiledProgram;
// MicroPython boards carry the 'micropython-loaded' sentinel instead of
// a flash image — nothing to write. Arduino/ESP-IDF sketches only.
const isMpy = board.languageMode === 'micropython';
const hasCompiled = !!board.compiledProgram && !isMpy;
return (
<div>
<div style={{ padding: 16, background: '#0c0c11', borderRadius: 4, marginBottom: 12 }}>
@ -418,7 +421,14 @@ const WebReadyView = ({ board, onFlash }: WebReadyProps) => {
</div>
</div>
{!hasCompiled && (
{isMpy && (
<div style={{ padding: 10, background: '#3a2e1a', color: '#ffb84d', borderRadius: 4, fontSize: 12, marginBottom: 12 }}>
MicroPython projects cannot be flashed to a real board yet — only
compiled Arduino/ESP-IDF sketches.
</div>
)}
{!board.compiledProgram && !isMpy && (
<div style={{ padding: 10, background: '#3a2e1a', color: '#ffb84d', borderRadius: 4, fontSize: 12, marginBottom: 12 }}>
No compiled program for this board yet. Click Compile in the toolbar first.
</div>

View File

@ -3447,13 +3447,19 @@ export const SimulatorCanvas = ({ headerSlot }: SimulatorCanvasProps = {}) => {
// on the web the pro overlay may install a Web Serial flasher
// for this board kind (no-op in pure OSS builds).
if (isTauriRuntime || webFlashAvailable(board.boardKind)) {
// MicroPython boards don't compile to a flash image — the store
// keeps the 'micropython-loaded' sentinel, which no flasher can
// write. Arduino/ESP-IDF sketches only.
const isMpy = board.languageMode === 'micropython';
actions.push({
id: 'flash',
label: t('editor.canvas.flashToBoard'),
disabled: !board.compiledProgram,
title: board.compiledProgram
? 'Flash the compiled sketch to a real USB-attached board'
: 'Compile the sketch first',
disabled: !board.compiledProgram || isMpy,
title: isMpy
? 'MicroPython projects cannot be flashed yet — Arduino sketches only'
: board.compiledProgram
? 'Flash the compiled sketch to a real USB-attached board'
: 'Compile the sketch first',
onSelect: () => {
setFlashModalFor(boardContextMenu.boardId);
setBoardContextMenu(null);