Skip to content

Commit 807f0ac

Browse files
committed
Fix embedded FletApp stdout/stderr dropped by the framed transport
The Pyodide↔Dart postMessage transport frames every packet as [type:u8][payload] (0x00 = MsgPack Flet protocol frame, 0x01 = raw DataChannel frame), and PyodideConnection.send_message prepends the 0x00 byte. The python_output shim, however, posted the raw msgpack [7, {...}] with no type byte, so the Dart side read msgpack's leading 0x92 (array-of-2 marker) as an unknown packet type and silently dropped every stdout/stderr line — the host page's Console pane never saw embedded-app output. Prepend the 0x00 type byte in both worker templates (client + cookiecutter build template).
1 parent ec0e821 commit 807f0ac

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

client/web/python-worker.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,15 @@ self.initPyodide = async function () {
170170
import msgpack as _msgpack
171171
172172
def _send_python_output(text, is_stderr):
173+
# Frame exactly like PyodideConnection.send_message: a 0x00 type
174+
# byte (0x00 = MsgPack Flet protocol frame, 0x01 = raw DataChannel
175+
# frame) in front of the packed [action, body]. Without the prefix
176+
# the Dart side reads msgpack's leading 0x92 as an unknown packet
177+
# type and silently drops the line. bytes([0]) avoids a literal
178+
# NUL escape inside this JS template string.
173179
flet_js.receive_callback(
174-
_msgpack.packb(
180+
bytes([0])
181+
+ _msgpack.packb(
175182
[7, {"text": text, "is_stderr": bool(is_stderr)}]
176183
)
177184
)

sdk/python/templates/build/{{cookiecutter.out_dir}}/web/python-worker.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,15 @@ self.initPyodide = async function () {
170170
import msgpack as _msgpack
171171
172172
def _send_python_output(text, is_stderr):
173+
# Frame exactly like PyodideConnection.send_message: a 0x00 type
174+
# byte (0x00 = MsgPack Flet protocol frame, 0x01 = raw DataChannel
175+
# frame) in front of the packed [action, body]. Without the prefix
176+
# the Dart side reads msgpack's leading 0x92 as an unknown packet
177+
# type and silently drops the line. bytes([0]) avoids a literal
178+
# NUL escape inside this JS template string.
173179
flet_js.receive_callback(
174-
_msgpack.packb(
180+
bytes([0])
181+
+ _msgpack.packb(
175182
[7, {"text": text, "is_stderr": bool(is_stderr)}]
176183
)
177184
)

0 commit comments

Comments
 (0)