@marimo-team/frontend 0.23.16-dev35 → 0.23.16-dev37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CellStatus-CmojVYzm.js → CellStatus-C6Cj3oJc.js} +1 -1
- package/dist/assets/{JsonOutput-BwwRpByA.js → JsonOutput-CyzvjIjx.js} +12 -12
- package/dist/assets/{MarimoErrorOutput-BWte8vjk.js → MarimoErrorOutput-CIuzXFFo.js} +4 -4
- package/dist/assets/{RenderHTML-DRltV71H.js → RenderHTML-Cd-PP5ZR.js} +1 -1
- package/dist/assets/{RunButton-DIegd2mN.js → RunButton-CnYWedW4.js} +1 -1
- package/dist/assets/{add-cell-with-ai-BBFD-M9V.js → add-cell-with-ai-ByOBQT99.js} +17 -17
- package/dist/assets/{add-connection-dialog-CECJ8507.js → add-connection-dialog-C97ylgk0.js} +1 -1
- package/dist/assets/{agent-panel-YaS0WXP1.js → agent-panel-Dxo9WUKV.js} +4 -4
- package/dist/assets/ai-model-dropdown-Bvqy98cI.js +5 -0
- package/dist/assets/{app-config-button-BW-w01aF.js → app-config-button-v1lG63C2.js} +1 -1
- package/dist/assets/{cell-editor-EV-1IccQ.js → cell-editor-BKrHbyX_.js} +16 -16
- package/dist/assets/cell-link-w5IbCQV4.js +1 -0
- package/dist/assets/cells-DzyDERZy.js +235 -0
- package/dist/assets/{chat-display-8BbC5B-D.js → chat-display-Ccgk4vbE.js} +1 -1
- package/dist/assets/{chat-panel-CMOZp5xW.js → chat-panel--53TIc3t.js} +4 -4
- package/dist/assets/{chat-ui-DWhJ2Ozy.js → chat-ui-B5rBxgsw.js} +4 -4
- package/dist/assets/{column-preview-DeXESYpM.js → column-preview-Cb8R9kfl.js} +1 -1
- package/dist/assets/{command-palette-Dx6AkiPd.js → command-palette-B1S9PjZi.js} +1 -1
- package/dist/assets/{common-XVELED_O.js → common-CJ3baa6D.js} +1 -1
- package/dist/assets/{components-BLHpmhXx.js → components-DpUIWGaj.js} +1 -1
- package/dist/assets/{datasource-CTqa8bf-.js → datasource-D_VcQMEn.js} +2 -2
- package/dist/assets/{dependency-graph-panel-C4Nzcddp.js → dependency-graph-panel-DY5lvPDx.js} +4 -4
- package/dist/assets/{documentation-panel-Bym4G7IS.js → documentation-panel-CGhwxsXK.js} +1 -1
- package/dist/assets/{download-HKgqJX4l.js → download-DpS57jyt.js} +2 -2
- package/dist/assets/{edit-page-Jtp6Qqjl.js → edit-page-DA765yQV.js} +6 -6
- package/dist/assets/error-entries-CTYMwfsh.js +8 -0
- package/dist/assets/{error-panel-CfSy7uUr.js → error-panel-DGAkG5kW.js} +1 -1
- package/dist/assets/{file-explorer-panel-Dd5Xn2TK.js → file-explorer-panel-BKUo-MDh.js} +4 -4
- package/dist/assets/{file-icons-CSjJ3JC6.js → file-icons-DfWENcb8.js} +1 -1
- package/dist/assets/{file-name-input-CrKtrXMl.js → file-name-input-CNVZtm5K.js} +1 -1
- package/dist/assets/{floating-outline-ByQ8vvif.js → floating-outline-LitP0wCD.js} +1 -1
- package/dist/assets/{focus-CVONl-Dy.js → focus-CNKbm-Xz.js} +1 -1
- package/dist/assets/{form-Ca3yd_Od.js → form-nHzLTU1m.js} +2 -2
- package/dist/assets/{home-page-FpAawj9s.js → home-page-DM9Z_IJ7.js} +2 -2
- package/dist/assets/{html-to-image-C-4ysbGe.js → html-to-image-JaxFFZcr.js} +2 -2
- package/dist/assets/{index-CiJmYQBT.js → index-C7_REKh1.js} +7 -7
- package/dist/assets/{index-xs-zSSrX.css → index-D6Dp_PFj.css} +1 -1
- package/dist/assets/{layout-Dtql_o_T.js → layout-B29hqiiK.js} +5 -5
- package/dist/assets/logs-panel-CQRPYS8j.js +1 -0
- package/dist/assets/{markdown-renderer-dABDqZDw.js → markdown-renderer-sEayY9-m.js} +2 -2
- package/dist/assets/{name-cell-input-Y4knmEIU.js → name-cell-input-B-aj1KH3.js} +1 -1
- package/dist/assets/{outline-panel-CQ_KWLip.js → outline-panel-BOryk60D.js} +1 -1
- package/dist/assets/{packages-panel-Ijt7d51P.js → packages-panel-DoYDLty3.js} +1 -1
- package/dist/assets/{panels-DfU1Oikj.js → panels-Bb4fIHgH.js} +2 -2
- package/dist/assets/process-output-d-LEMtGI.js +1 -0
- package/dist/assets/{radio-group-22eWJ9fv.js → radio-group-DfioQthW.js} +1 -1
- package/dist/assets/readonly-code-display-C9fu8tvK.js +1 -0
- package/dist/assets/{readonly-python-code-n_TrLmsR.js → readonly-python-code-DHxOnQGj.js} +1 -1
- package/dist/assets/{reveal-component-CCLTV1q6.js → reveal-component-5jf0W625.js} +2 -2
- package/dist/assets/{run-page-DbezK7Qs.js → run-page-BMKx9ld_.js} +1 -1
- package/dist/assets/scratchpad-panel-C8z8vzBX.js +1 -0
- package/dist/assets/{session-panel-BZGNcZmp.js → session-panel-BVVk-02h.js} +1 -1
- package/dist/assets/{skeleton-BzlKcq21.js → skeleton-Bubr9pIj.js} +1 -1
- package/dist/assets/{snippets-panel-DNaNtkR0.js → snippets-panel-U2-iok-c.js} +1 -1
- package/dist/assets/{state-DFPAfLw7.js → state-DtziTd1T.js} +3 -3
- package/dist/assets/{state-jCdh8Dcx.js → state-DxQhUsG9.js} +1 -1
- package/dist/assets/{textarea-DuEtSOCl.js → textarea-Bmzmbbpo.js} +1 -1
- package/dist/assets/{tracing-ttUd3J7U.js → tracing-B5XFvMmV.js} +1 -1
- package/dist/assets/{tracing-panel-rVAa3En0.js → tracing-panel-DnR2bYDe.js} +2 -2
- package/dist/assets/{tree-actions-UCr1tMHw.js → tree-actions-Dx9CDaxV.js} +1 -1
- package/dist/assets/useCellActionButton-DypR3yDt.js +1 -0
- package/dist/assets/{useDeleteCell-PrgejW8A.js → useDeleteCell-vMXAr3rY.js} +1 -1
- package/dist/assets/{useDependencyPanelTab-5jc-_-hy.js → useDependencyPanelTab-CwdwKf7A.js} +1 -1
- package/dist/assets/{useNotebookActions-4vw_NiRs.js → useNotebookActions-jWIcmpv0.js} +3 -3
- package/dist/assets/useRunCells-C2dvU2jA.js +1 -0
- package/dist/assets/{useSplitCell-MZpER0Bh.js → useSplitCell-C1tubdNi.js} +1 -1
- package/dist/index.html +23 -23
- package/package.json +2 -3
- package/src/components/editor/cell/code/__tests__/cell-editor-activity-lifecycle.test.ts +250 -0
- package/src/components/editor/cell/code/cell-editor.tsx +13 -7
- package/src/components/editor/chrome/panels/__tests__/logs-panel.test.tsx +25 -0
- package/src/components/editor/chrome/panels/logs-panel.tsx +12 -2
- package/src/core/cells/__tests__/cells.test.ts +12 -2
- package/src/core/cells/__tests__/logs.test.ts +5 -5
- package/src/core/cells/cells.ts +17 -4
- package/src/core/cells/document-changes.ts +1 -0
- package/src/core/cells/logs.ts +14 -4
- package/src/core/codemirror/copilot/__tests__/language-server.test.ts +396 -100
- package/src/core/codemirror/copilot/__tests__/transport.test.ts +128 -540
- package/src/core/codemirror/copilot/language-server.ts +182 -70
- package/src/core/codemirror/copilot/transport.ts +15 -207
- package/src/core/codemirror/copilot/types.ts +9 -2
- package/src/core/codemirror/language/languages/python.ts +23 -11
- package/src/core/codemirror/lsp/__tests__/federated-lsp.test.ts +161 -0
- package/src/core/codemirror/lsp/__tests__/log-messages.test.ts +53 -0
- package/src/core/codemirror/lsp/__tests__/normalize-markdown-math.test.ts +25 -0
- package/src/core/codemirror/lsp/__tests__/notebook-lsp.test.ts +598 -156
- package/src/core/codemirror/lsp/__tests__/transports.test.ts +112 -0
- package/src/core/codemirror/lsp/federated-lsp.ts +76 -23
- package/src/core/codemirror/lsp/log-messages.ts +37 -0
- package/src/core/codemirror/lsp/normalize-markdown-math.ts +8 -4
- package/src/core/codemirror/lsp/notebook-lsp.ts +220 -56
- package/src/core/codemirror/lsp/transports.ts +8 -1
- package/src/core/codemirror/lsp/types.ts +68 -8
- package/src/core/codemirror/lsp/utils.ts +14 -0
- package/src/core/lsp/__tests__/transport.test.ts +509 -337
- package/src/core/lsp/transport.ts +304 -132
- package/src/core/rtc/state.ts +9 -0
- package/src/css/app/codemirror.css +16 -2
- package/src/stories/log-viewer.stories.tsx +12 -6
- package/dist/assets/ai-model-dropdown-BpVBUZnz.js +0 -5
- package/dist/assets/cell-link-C5gpAn3R.js +0 -1
- package/dist/assets/cells-6yd8nOAu.js +0 -231
- package/dist/assets/error-entries-CxyvaxEM.js +0 -8
- package/dist/assets/logs-panel-5u1wUBn1.js +0 -1
- package/dist/assets/process-output-Dd11YI04.js +0 -1
- package/dist/assets/readonly-code-display-BjK-TEri.js +0 -1
- package/dist/assets/scratchpad-panel-C2wAEv5n.js +0 -1
- package/dist/assets/useCellActionButton-CJknR0XY.js +0 -1
- package/dist/assets/useRunCells-DHsd7HGL.js +0 -1
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Simulates React Activity's effect teardown when mode switches to "hidden":
|
|
5
|
+
* all useEffect cleanups run. On "visible", setups re-run (cleanups do not run
|
|
6
|
+
* again). Component state and DOM are preserved — only effects cycle.
|
|
7
|
+
*
|
|
8
|
+
* Registration order matches cell-editor.tsx: mount effect runs before destroy
|
|
9
|
+
* effect setup. With async editor creation (editorMountScheduler), destroy
|
|
10
|
+
* captures null initially; with sync creation it captures the live editor.
|
|
11
|
+
*/
|
|
12
|
+
import { EditorState } from "@codemirror/state";
|
|
13
|
+
import { EditorView } from "@codemirror/view";
|
|
14
|
+
import { describe, expect, it } from "vitest";
|
|
15
|
+
import { Functions } from "@/utils/functions";
|
|
16
|
+
|
|
17
|
+
interface EffectRegistration {
|
|
18
|
+
cleanup: () => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function createActivitySimulator() {
|
|
22
|
+
const effects: EffectRegistration[] = [];
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
/** Register effects in order — each setup runs synchronously, like React. */
|
|
26
|
+
useEffect(setup: () => (() => void) | undefined) {
|
|
27
|
+
const cleanup = setup() ?? Functions.NOOP;
|
|
28
|
+
effects.push({ cleanup });
|
|
29
|
+
},
|
|
30
|
+
hide() {
|
|
31
|
+
for (const effect of effects) {
|
|
32
|
+
effect.cleanup();
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
show() {
|
|
36
|
+
effects.length = 0;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function createEditor(doc = "hello") {
|
|
42
|
+
return new EditorView({
|
|
43
|
+
state: EditorState.create({ doc }),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface RegisterCellEditorEffectsOptions {
|
|
48
|
+
activity: ReturnType<typeof createActivitySimulator>;
|
|
49
|
+
editorViewRef: { current: EditorView | null };
|
|
50
|
+
destroyPattern: "old" | "pr";
|
|
51
|
+
onDestroy?: () => void;
|
|
52
|
+
/** When true, editor creation is deferred like editorMountScheduler.request */
|
|
53
|
+
asyncMount?: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function registerCellEditorEffects({
|
|
57
|
+
activity,
|
|
58
|
+
editorViewRef,
|
|
59
|
+
destroyPattern,
|
|
60
|
+
onDestroy,
|
|
61
|
+
asyncMount = false,
|
|
62
|
+
}: RegisterCellEditorEffectsOptions) {
|
|
63
|
+
activity.useEffect(() => {
|
|
64
|
+
if (editorViewRef.current !== null) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
let cancelled = false;
|
|
68
|
+
const mount = () => {
|
|
69
|
+
if (!cancelled && editorViewRef.current === null) {
|
|
70
|
+
editorViewRef.current = createEditor();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
if (asyncMount) {
|
|
74
|
+
const id = setTimeout(mount, 0);
|
|
75
|
+
return () => {
|
|
76
|
+
cancelled = true;
|
|
77
|
+
clearTimeout(id);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
mount();
|
|
81
|
+
return () => {
|
|
82
|
+
cancelled = true;
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (destroyPattern === "old") {
|
|
87
|
+
activity.useEffect(() => {
|
|
88
|
+
const ev = editorViewRef.current;
|
|
89
|
+
return () => {
|
|
90
|
+
if (ev) {
|
|
91
|
+
ev.destroy();
|
|
92
|
+
onDestroy?.();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
} else {
|
|
97
|
+
activity.useEffect(() => {
|
|
98
|
+
return () => {
|
|
99
|
+
if (editorViewRef.current) {
|
|
100
|
+
editorViewRef.current.destroy();
|
|
101
|
+
onDestroy?.();
|
|
102
|
+
}
|
|
103
|
+
editorViewRef.current = null;
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
describe("CellEditor Activity lifecycle (simulated)", () => {
|
|
110
|
+
it("old destroy pattern (sync mount): first hide/show leaves stale ref", () => {
|
|
111
|
+
const editorViewRef = { current: null as EditorView | null };
|
|
112
|
+
let destroyCount = 0;
|
|
113
|
+
const activity = createActivitySimulator();
|
|
114
|
+
|
|
115
|
+
registerCellEditorEffects({
|
|
116
|
+
activity,
|
|
117
|
+
editorViewRef,
|
|
118
|
+
destroyPattern: "old",
|
|
119
|
+
onDestroy: () => {
|
|
120
|
+
destroyCount++;
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
const liveEditor = editorViewRef.current;
|
|
124
|
+
expect(liveEditor).not.toBeNull();
|
|
125
|
+
|
|
126
|
+
activity.hide();
|
|
127
|
+
expect(destroyCount).toBeGreaterThan(0);
|
|
128
|
+
expect(editorViewRef.current).toBe(liveEditor);
|
|
129
|
+
|
|
130
|
+
activity.show();
|
|
131
|
+
registerCellEditorEffects({
|
|
132
|
+
activity,
|
|
133
|
+
editorViewRef,
|
|
134
|
+
destroyPattern: "old",
|
|
135
|
+
});
|
|
136
|
+
expect(editorViewRef.current).toBe(liveEditor);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("old destroy pattern (async mount): first hide/show preserves editor", async () => {
|
|
140
|
+
const editorViewRef = { current: null as EditorView | null };
|
|
141
|
+
let destroyCount = 0;
|
|
142
|
+
const activity = createActivitySimulator();
|
|
143
|
+
|
|
144
|
+
registerCellEditorEffects({
|
|
145
|
+
activity,
|
|
146
|
+
editorViewRef,
|
|
147
|
+
destroyPattern: "old",
|
|
148
|
+
onDestroy: () => {
|
|
149
|
+
destroyCount++;
|
|
150
|
+
},
|
|
151
|
+
asyncMount: true,
|
|
152
|
+
});
|
|
153
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
154
|
+
const liveEditor = editorViewRef.current;
|
|
155
|
+
expect(liveEditor).not.toBeNull();
|
|
156
|
+
|
|
157
|
+
// Destroy effect captured null at setup (editor created async after effects)
|
|
158
|
+
activity.hide();
|
|
159
|
+
expect(destroyCount).toBe(0);
|
|
160
|
+
expect(editorViewRef.current).toBe(liveEditor);
|
|
161
|
+
|
|
162
|
+
activity.show();
|
|
163
|
+
registerCellEditorEffects({
|
|
164
|
+
activity,
|
|
165
|
+
editorViewRef,
|
|
166
|
+
destroyPattern: "old",
|
|
167
|
+
asyncMount: true,
|
|
168
|
+
});
|
|
169
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
170
|
+
expect(editorViewRef.current).toBe(liveEditor);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("PR destroy pattern (async mount): recreates on first hide/show", async () => {
|
|
174
|
+
const editorViewRef = { current: null as EditorView | null };
|
|
175
|
+
const activity = createActivitySimulator();
|
|
176
|
+
|
|
177
|
+
registerCellEditorEffects({
|
|
178
|
+
activity,
|
|
179
|
+
editorViewRef,
|
|
180
|
+
destroyPattern: "pr",
|
|
181
|
+
asyncMount: true,
|
|
182
|
+
});
|
|
183
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
184
|
+
const firstEditor = editorViewRef.current;
|
|
185
|
+
|
|
186
|
+
activity.hide();
|
|
187
|
+
expect(editorViewRef.current).toBeNull();
|
|
188
|
+
|
|
189
|
+
activity.show();
|
|
190
|
+
registerCellEditorEffects({
|
|
191
|
+
activity,
|
|
192
|
+
editorViewRef,
|
|
193
|
+
destroyPattern: "pr",
|
|
194
|
+
asyncMount: true,
|
|
195
|
+
});
|
|
196
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
197
|
+
expect(editorViewRef.current).not.toBeNull();
|
|
198
|
+
expect(editorViewRef.current).not.toBe(firstEditor);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("PR destroy pattern: nulls ref on hide so mount recreates on show", () => {
|
|
202
|
+
const editorViewRef = { current: null as EditorView | null };
|
|
203
|
+
const activity = createActivitySimulator();
|
|
204
|
+
|
|
205
|
+
registerCellEditorEffects({
|
|
206
|
+
activity,
|
|
207
|
+
editorViewRef,
|
|
208
|
+
destroyPattern: "pr",
|
|
209
|
+
});
|
|
210
|
+
const firstEditor = editorViewRef.current;
|
|
211
|
+
|
|
212
|
+
activity.hide();
|
|
213
|
+
expect(editorViewRef.current).toBeNull();
|
|
214
|
+
|
|
215
|
+
activity.show();
|
|
216
|
+
registerCellEditorEffects({
|
|
217
|
+
activity,
|
|
218
|
+
editorViewRef,
|
|
219
|
+
destroyPattern: "pr",
|
|
220
|
+
});
|
|
221
|
+
expect(editorViewRef.current).not.toBeNull();
|
|
222
|
+
expect(editorViewRef.current).not.toBe(firstEditor);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("PR destroy pattern: stable across repeated hide/show cycles", () => {
|
|
226
|
+
const editorViewRef = { current: null as EditorView | null };
|
|
227
|
+
const activity = createActivitySimulator();
|
|
228
|
+
|
|
229
|
+
for (let i = 0; i < 3; i++) {
|
|
230
|
+
registerCellEditorEffects({
|
|
231
|
+
activity,
|
|
232
|
+
editorViewRef,
|
|
233
|
+
destroyPattern: "pr",
|
|
234
|
+
});
|
|
235
|
+
expect(editorViewRef.current).not.toBeNull();
|
|
236
|
+
|
|
237
|
+
activity.hide();
|
|
238
|
+
expect(editorViewRef.current).toBeNull();
|
|
239
|
+
|
|
240
|
+
activity.show();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
registerCellEditorEffects({
|
|
244
|
+
activity,
|
|
245
|
+
editorViewRef,
|
|
246
|
+
destroyPattern: "pr",
|
|
247
|
+
});
|
|
248
|
+
expect(editorViewRef.current).not.toBeNull();
|
|
249
|
+
});
|
|
250
|
+
});
|
|
@@ -39,7 +39,7 @@ import type { UserConfig } from "@/core/config/config-schema";
|
|
|
39
39
|
import { OverridingHotkeyProvider } from "@/core/hotkeys/hotkeys";
|
|
40
40
|
import { connectionAtom } from "@/core/network/connection";
|
|
41
41
|
import { useRequestClient } from "@/core/network/requests";
|
|
42
|
-
import { isRtcEnabled } from "@/core/rtc/state";
|
|
42
|
+
import { canUseRtc, isRtcEnabled } from "@/core/rtc/state";
|
|
43
43
|
import { useSaveNotebook } from "@/core/saving/save-component";
|
|
44
44
|
import { isAppConnecting } from "@/core/websocket/connection-utils";
|
|
45
45
|
import type { Theme } from "@/theme/useTheme";
|
|
@@ -342,7 +342,7 @@ const CellEditorInternal = ({
|
|
|
342
342
|
saveOrNameNotebook,
|
|
343
343
|
]);
|
|
344
344
|
|
|
345
|
-
const rtcEnabled = isRtcEnabled();
|
|
345
|
+
const rtcEnabled = isRtcEnabled() && canUseRtc(cellId);
|
|
346
346
|
const handleInitializeEditor = useEvent(() => {
|
|
347
347
|
// If rtc is enabled, use collaborative editing
|
|
348
348
|
if (rtcEnabled) {
|
|
@@ -451,6 +451,7 @@ const CellEditorInternal = ({
|
|
|
451
451
|
setIsEditorMounted(true);
|
|
452
452
|
return;
|
|
453
453
|
}
|
|
454
|
+
setIsEditorMounted(false);
|
|
454
455
|
if (serializedEditorState !== null) {
|
|
455
456
|
handleDeserializeEditor();
|
|
456
457
|
setIsEditorMounted(true);
|
|
@@ -479,11 +480,12 @@ const CellEditorInternal = ({
|
|
|
479
480
|
handleReconfigureEditor();
|
|
480
481
|
}, [handleReconfigureEditor, extensions, editorViewRef]);
|
|
481
482
|
|
|
482
|
-
// Destroy the editor when the component is unmounted
|
|
483
|
+
// Destroy the editor when the component is unmounted. Read the ref in cleanup
|
|
484
|
+
// (not setup) so Activity hide/show cycles don't leave a stale destroyed view.
|
|
483
485
|
useEffect(() => {
|
|
484
|
-
const ev = editorViewRef.current;
|
|
485
486
|
return () => {
|
|
486
|
-
|
|
487
|
+
editorViewRef.current?.destroy();
|
|
488
|
+
editorViewRef.current = null;
|
|
487
489
|
};
|
|
488
490
|
}, [editorViewRef]);
|
|
489
491
|
|
|
@@ -635,14 +637,18 @@ CellCodeMirrorEditor.displayName = "CellCodeMirrorEditor";
|
|
|
635
637
|
// Wait until the websocket connection is open before rendering the editor
|
|
636
638
|
// This is used for real-time collaboration since the backend needs the connection started
|
|
637
639
|
// before connecting the rtc websockets
|
|
638
|
-
function WithWaitUntilConnected<T extends
|
|
640
|
+
function WithWaitUntilConnected<T extends Pick<CellEditorProps, "id">>(
|
|
639
641
|
Component: React.ComponentType<T>,
|
|
640
642
|
) {
|
|
641
643
|
const WaitUntilConnectedComponent = (props: T) => {
|
|
642
644
|
const connection = useAtomValue(connectionAtom);
|
|
643
645
|
const [rtcDoc, setRtcDoc] = useAtom(connectedDocAtom);
|
|
644
646
|
|
|
645
|
-
if (
|
|
647
|
+
if (
|
|
648
|
+
isRtcEnabled() &&
|
|
649
|
+
canUseRtc(props.id) &&
|
|
650
|
+
(isAppConnecting(connection.state) || rtcDoc === undefined)
|
|
651
|
+
) {
|
|
646
652
|
return (
|
|
647
653
|
<div className="flex h-full w-full items-baseline p-4">
|
|
648
654
|
<DelayMount milliseconds={1000} fallback={null}>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import type { CellLog } from "@/core/cells/logs";
|
|
6
|
+
import { LogViewer } from "../logs-panel";
|
|
7
|
+
|
|
8
|
+
describe("LogViewer", () => {
|
|
9
|
+
it("labels logs that came from a language server instead of a cell", () => {
|
|
10
|
+
const logs: CellLog[] = [
|
|
11
|
+
{
|
|
12
|
+
timestamp: 0,
|
|
13
|
+
level: "stderr",
|
|
14
|
+
message: "pylsp failed to start",
|
|
15
|
+
source: { type: "lsp", name: "pylsp" },
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
render(<LogViewer logs={logs} />);
|
|
20
|
+
|
|
21
|
+
expect(screen.getByText("(lsp:pylsp)")).toBeInTheDocument();
|
|
22
|
+
expect(screen.getByText("pylsp failed to start")).toBeInTheDocument();
|
|
23
|
+
expect(screen.getByText("STDERR")).toBeInTheDocument();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -4,7 +4,11 @@ import { FileTextIcon } from "lucide-react";
|
|
|
4
4
|
import React from "react";
|
|
5
5
|
import { ClearButton } from "@/components/buttons/clear-button";
|
|
6
6
|
import { useCellActions, useCellLogs } from "@/core/cells/cells";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
type CellLog,
|
|
9
|
+
formatLogTimestamp,
|
|
10
|
+
logSourceLabel,
|
|
11
|
+
} from "@/core/cells/logs";
|
|
8
12
|
import { cn } from "@/utils/cn";
|
|
9
13
|
import { CellLink } from "../../links/cell-link";
|
|
10
14
|
import { PanelEmptyState } from "./empty-state";
|
|
@@ -84,7 +88,13 @@ function formatLog(log: CellLog) {
|
|
|
84
88
|
</span>
|
|
85
89
|
<span className={cn("shrink-0", color)}>{level}</span>
|
|
86
90
|
<span className="shrink-0 text-(--gray-10)">
|
|
87
|
-
(
|
|
91
|
+
(
|
|
92
|
+
{log.source.type === "cell" ? (
|
|
93
|
+
<CellLink cellId={log.source.cellId} />
|
|
94
|
+
) : (
|
|
95
|
+
logSourceLabel(log.source)
|
|
96
|
+
)}
|
|
97
|
+
)
|
|
88
98
|
</span>
|
|
89
99
|
{log.message}
|
|
90
100
|
</>
|
|
@@ -1870,8 +1870,18 @@ describe("cell reducer", () => {
|
|
|
1870
1870
|
|
|
1871
1871
|
it("can clear logs", () => {
|
|
1872
1872
|
state.cellLogs = [
|
|
1873
|
-
{
|
|
1874
|
-
|
|
1873
|
+
{
|
|
1874
|
+
level: "stderr",
|
|
1875
|
+
message: "log1",
|
|
1876
|
+
timestamp: 0,
|
|
1877
|
+
source: { type: "cell", cellId: firstCellId },
|
|
1878
|
+
},
|
|
1879
|
+
{
|
|
1880
|
+
level: "stderr",
|
|
1881
|
+
message: "log1",
|
|
1882
|
+
timestamp: 0,
|
|
1883
|
+
source: { type: "cell", cellId: firstCellId },
|
|
1884
|
+
},
|
|
1875
1885
|
];
|
|
1876
1886
|
actions.clearLogs();
|
|
1877
1887
|
expect(state.cellLogs).toEqual([]);
|
|
@@ -46,7 +46,7 @@ describe("getCellLogsForMessage", () => {
|
|
|
46
46
|
timestamp: 1_234_567_890,
|
|
47
47
|
level: "stdout",
|
|
48
48
|
message: "Hello, World!",
|
|
49
|
-
cellId: "cell-1",
|
|
49
|
+
source: { type: "cell", cellId: "cell-1" },
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
52
|
|
|
@@ -74,7 +74,7 @@ describe("getCellLogsForMessage", () => {
|
|
|
74
74
|
timestamp: 1_234_567_890,
|
|
75
75
|
level: "stderr",
|
|
76
76
|
message: "Error occurred",
|
|
77
|
-
cellId: "cell-2",
|
|
77
|
+
source: { type: "cell", cellId: "cell-2" },
|
|
78
78
|
});
|
|
79
79
|
});
|
|
80
80
|
|
|
@@ -102,7 +102,7 @@ describe("getCellLogsForMessage", () => {
|
|
|
102
102
|
timestamp: 1_234_567_890,
|
|
103
103
|
level: "stdout",
|
|
104
104
|
message: "Error: Something went wrong",
|
|
105
|
-
cellId: "cell-3",
|
|
105
|
+
source: { type: "cell", cellId: "cell-3" },
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
108
|
|
|
@@ -130,7 +130,7 @@ describe("getCellLogsForMessage", () => {
|
|
|
130
130
|
timestamp: 1_234_567_890,
|
|
131
131
|
level: "stderr",
|
|
132
132
|
message: "Critical Error: System failure",
|
|
133
|
-
cellId: "cell-4",
|
|
133
|
+
source: { type: "cell", cellId: "cell-4" },
|
|
134
134
|
});
|
|
135
135
|
});
|
|
136
136
|
|
|
@@ -157,7 +157,7 @@ describe("getCellLogsForMessage", () => {
|
|
|
157
157
|
expect(logs[0].level).toBe("stderr"); // marimo-error should be treated as stderr
|
|
158
158
|
expect(logs[0].message).toContain("Traceback (most recent call last):");
|
|
159
159
|
expect(logs[0].message).toContain('File "test.py", line 1');
|
|
160
|
-
expect(logs[0].
|
|
160
|
+
expect(logs[0].source).toEqual({ type: "cell", cellId: "cell-5" });
|
|
161
161
|
});
|
|
162
162
|
|
|
163
163
|
test("handles multiple console outputs with different MIME types", () => {
|
package/src/core/cells/cells.ts
CHANGED
|
@@ -28,7 +28,7 @@ import { findCollapseRange, mergeOutlines } from "../dom/outline";
|
|
|
28
28
|
import type { CellMessage } from "../kernel/messages";
|
|
29
29
|
import { isErrorMime } from "../mime";
|
|
30
30
|
import type { CellConfig } from "../network/types";
|
|
31
|
-
import { isRtcEnabled } from "../rtc/state";
|
|
31
|
+
import { canUseRtc, isRtcEnabled } from "../rtc/state";
|
|
32
32
|
import { createDeepEqualAtom, store } from "../state/jotai";
|
|
33
33
|
import { isWasm } from "../wasm/utils";
|
|
34
34
|
import { prepareCellForExecution, transitionCell } from "./cell";
|
|
@@ -927,6 +927,12 @@ const {
|
|
|
927
927
|
cellLogs: [...nextState.cellLogs, ...getCellLogsForMessage(message)],
|
|
928
928
|
};
|
|
929
929
|
},
|
|
930
|
+
addLogs: (state, action: { logs: CellLog[] }) => {
|
|
931
|
+
return {
|
|
932
|
+
...state,
|
|
933
|
+
cellLogs: [...state.cellLogs, ...action.logs],
|
|
934
|
+
};
|
|
935
|
+
},
|
|
930
936
|
setCellIds: (state, action: { cellIds: CellId[] }) => {
|
|
931
937
|
const isTheSame = isEqual(state.cellIds.inOrderIds, action.cellIds);
|
|
932
938
|
if (isTheSame) {
|
|
@@ -1037,9 +1043,9 @@ const {
|
|
|
1037
1043
|
};
|
|
1038
1044
|
}
|
|
1039
1045
|
|
|
1040
|
-
// Update codemirror if mounted
|
|
1041
|
-
//
|
|
1042
|
-
if (!isRtcEnabled()) {
|
|
1046
|
+
// Update codemirror if mounted. RTC-backed cells sync via Loro; others
|
|
1047
|
+
// (e.g. scratchpad) still need an explicit editor update.
|
|
1048
|
+
if (!isRtcEnabled() || !canUseRtc(cellId)) {
|
|
1043
1049
|
const cellHandle = nextState.cellHandles[cellId].current;
|
|
1044
1050
|
if (cellHandle?.editorViewOrNull) {
|
|
1045
1051
|
updateEditorCodeFromPython(cellHandle.editorViewOrNull, code);
|
|
@@ -1698,6 +1704,13 @@ export {
|
|
|
1698
1704
|
notebookAtom,
|
|
1699
1705
|
};
|
|
1700
1706
|
|
|
1707
|
+
/** Actions for dispatching outside of React. */
|
|
1708
|
+
const imperativeActions = createActions((action) => {
|
|
1709
|
+
store.set(notebookAtom, (state) => reducer(state, action));
|
|
1710
|
+
});
|
|
1711
|
+
|
|
1712
|
+
export const addLogs = imperativeActions.addLogs;
|
|
1713
|
+
|
|
1701
1714
|
/// ATOMS
|
|
1702
1715
|
|
|
1703
1716
|
export const cellIdsAtom = atom((get) => get(notebookAtom).cellIds);
|
package/src/core/cells/logs.ts
CHANGED
|
@@ -13,11 +13,21 @@ import { tracebackModalAtom } from "../errors/traceback-atom";
|
|
|
13
13
|
import React from "react";
|
|
14
14
|
import { ToastAction } from "@/components/ui/toast";
|
|
15
15
|
|
|
16
|
+
/** Logs come from a cell, or from a language server, which has no cell. */
|
|
17
|
+
export type LogSource =
|
|
18
|
+
| { type: "cell"; cellId: CellId }
|
|
19
|
+
| { type: "lsp"; name: string };
|
|
20
|
+
|
|
16
21
|
export interface CellLog {
|
|
22
|
+
/** Unix timestamp, in seconds. */
|
|
17
23
|
timestamp: number;
|
|
18
24
|
level: "stdout" | "stderr";
|
|
19
25
|
message: string;
|
|
20
|
-
|
|
26
|
+
source: LogSource;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function logSourceLabel(source: LogSource): string {
|
|
30
|
+
return source.type === "cell" ? source.cellId : `lsp:${source.name}`;
|
|
21
31
|
}
|
|
22
32
|
|
|
23
33
|
let didAlreadyToastError = false;
|
|
@@ -48,7 +58,7 @@ export function getCellLogsForMessage(cell: CellMessage): CellLog[] {
|
|
|
48
58
|
timestamp: output.timestamp || Date.now(),
|
|
49
59
|
level: isError ? "stderr" : "stdout",
|
|
50
60
|
message: message,
|
|
51
|
-
cellId: cell.cell_id,
|
|
61
|
+
source: { type: "cell", cellId: cell.cell_id },
|
|
52
62
|
});
|
|
53
63
|
break;
|
|
54
64
|
}
|
|
@@ -71,7 +81,7 @@ export function getCellLogsForMessage(cell: CellMessage): CellLog[] {
|
|
|
71
81
|
cell.output.data.forEach((error) => {
|
|
72
82
|
CellLogLogger.log({
|
|
73
83
|
level: "stderr",
|
|
74
|
-
cellId: cell.cell_id,
|
|
84
|
+
source: { type: "cell", cellId: cell.cell_id },
|
|
75
85
|
timestamp: cell.timestamp ?? 0,
|
|
76
86
|
message: JSON.stringify(error),
|
|
77
87
|
});
|
|
@@ -150,7 +160,7 @@ const CellLogLogger = {
|
|
|
150
160
|
`%c[${status}]`,
|
|
151
161
|
`color:${color}; padding:2px 0; border-radius:2px; font-weight:bold`,
|
|
152
162
|
`[${formatLogTimestamp(payload.timestamp)}]`,
|
|
153
|
-
`(${payload.
|
|
163
|
+
`(${logSourceLabel(payload.source)}) ${payload.message}`,
|
|
154
164
|
);
|
|
155
165
|
},
|
|
156
166
|
};
|