@marimo-team/islands 0.25.3-dev373 → 0.25.3-dev375
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/{ConnectedDataExplorerComponent-BzohsNSl.js → ConnectedDataExplorerComponent-BpCrAeX0.js} +9 -9
- package/dist/{ErrorBoundary-CBhEVnmj.js → ErrorBoundary-Bceanw8E.js} +6 -6
- package/dist/{abnfDiagram-VCTEODGH-ChqGZ2ry.js → abnfDiagram-VCTEODGH-ZqNgGZlz.js} +2 -2
- package/dist/{any-language-editor-jTRRyM00.js → any-language-editor-CFbAr7vc.js} +2 -2
- package/dist/{architectureDiagram-5GKGNRK7-CnN59kY1.js → architectureDiagram-5GKGNRK7-BEUaR96d.js} +1 -1
- package/dist/{assertNever-C77RgMvO.js → assertNever-5uYEbJc8.js} +2 -2
- package/dist/{chat-ui-DfIJW9DA.js → chat-ui-BKSYhGMh.js} +12 -12
- package/dist/{check-BTtJ1HuS.js → check-BbhVyViy.js} +1 -1
- package/dist/{chunk-IMKFNOWR-DW_he6xH.js → chunk-IMKFNOWR-BdEPmWQI.js} +1 -1
- package/dist/{chunk-SHT3W25Y-rRSc_SiF.js → chunk-SHT3W25Y-IvvXM3xf.js} +1 -1
- package/dist/{chunk-SVP7TREG-B_G3ACtc.js → chunk-SVP7TREG-C_qpJUv1.js} +1 -1
- package/dist/{chunk-TICWLB2K-Bdqk9L9O.js → chunk-TICWLB2K-C4agYVWP.js} +1 -1
- package/dist/{classDiagram-ZZMXUADV-bkoIJ4ZI.js → classDiagram-ZZMXUADV-CT2iq8uF.js} +2 -2
- package/dist/{classDiagram-v2-VYDZK3BY-QvUGvghM.js → classDiagram-v2-VYDZK3BY-Coe_dD0r.js} +2 -2
- package/dist/{code-visibility-P2WZ3qgF.js → code-visibility-CxtxLHrv.js} +5 -5
- package/dist/{common-BGrRKU0g.js → common-SqvtVOs2.js} +19 -19
- package/dist/{config-D9r7V8wm.js → config-DJ8M-gPL.js} +3 -3
- package/dist/{copy-icon-AmDlztRw.js → copy-icon-xWvA8ybp.js} +2 -2
- package/dist/{createReducer-iKO-TaDo.js → createReducer-fp0gX_9U.js} +1 -1
- package/dist/{cynefinDiagram-5FMLGOSQ-BtDkWTBE.js → cynefinDiagram-5FMLGOSQ-D0LKziUu.js} +1 -1
- package/dist/{dagre-GXQ25YYZ-D0at1MO5.js → dagre-GXQ25YYZ-Cmgziaw8.js} +1 -1
- package/dist/{data-grid-overlay-editor-DkDG8asb.js → data-grid-overlay-editor-QC6ZFp8P.js} +1 -1
- package/dist/{diagram-S7CK7UJ4-DeEaMqSV.js → diagram-S7CK7UJ4-D-lZsALU.js} +1 -1
- package/dist/{diagram-UQ7AKVKN-BbRfuaEy.js → diagram-UQ7AKVKN-TcbdsFoT.js} +1 -1
- package/dist/{diagram-VX7I27RA-B4Wp-rDT.js → diagram-VX7I27RA-D5BqZi1q.js} +1 -1
- package/dist/{diagram-Z3DM3KII-C_ae4cSF.js → diagram-Z3DM3KII-MNc7jqvr.js} +1 -1
- package/dist/{dialog-Daog9NU1.js → dialog-Cm0VGdxc.js} +2 -2
- package/dist/{dropdown-menu-CnoeAarE.js → dropdown-menu-DfamXjVI.js} +5 -5
- package/dist/{ebnfDiagram-PWID7BFC-BPTzY6rk.js → ebnfDiagram-PWID7BFC-Cxt6ywyX.js} +2 -2
- package/dist/{erDiagram-RLTQ6QDP-udqrzZ59.js → erDiagram-RLTQ6QDP-BLF-askI.js} +1 -1
- package/dist/{error-banner-ChszWQ3h.js → error-banner-k06CAftu.js} +1 -1
- package/dist/{error-entries-IU7i5tD8.js → error-entries-rtPWQkJk.js} +10 -10
- package/dist/{feedback-button-hJmlXItP.js → feedback-button-VpqMqF9W.js} +8 -8
- package/dist/{flowDiagram-HODETNUW-CU1S_qjB.js → flowDiagram-HODETNUW-CsLw2mWn.js} +2 -2
- package/dist/{formats-B85hYR8d.js → formats-DQ-qq-dU.js} +1 -1
- package/dist/{glide-data-editor-DTflymx8.js → glide-data-editor-Bb6KYYMs.js} +11 -11
- package/dist/{glide-utils-DPwU6aTw.js → glide-utils-CHrghEu-.js} +2 -2
- package/dist/{globals-DyhQVCCv.js → globals-BarVvbhM.js} +3 -3
- package/dist/{html-to-image-BiNaAyYX.js → html-to-image-B5nTOeMI.js} +13 -13
- package/dist/{infoDiagram-27XIBGKW-DKkp_SC7.js → infoDiagram-27XIBGKW-CdSApBWg.js} +1 -1
- package/dist/{ishikawaDiagram-5VMMS53U-C_TlrS-s.js → ishikawaDiagram-5VMMS53U-BnzQ8SI5.js} +1 -1
- package/dist/{kanban-definition-UXKFOSKX-CoqGlHyo.js → kanban-definition-UXKFOSKX-D2llTpeX.js} +1 -1
- package/dist/main.js +3332 -3295
- package/dist/{mermaid-DD6lvLSi.js → mermaid-BcNMyKmf.js} +34 -34
- package/dist/{mindmap-definition-YA3MSWOX-DQ3RIRq_.js → mindmap-definition-YA3MSWOX-uoEsfD5R.js} +1 -1
- package/dist/{number-overlay-editor-D88EwUgZ.js → number-overlay-editor-CzSb_u5N.js} +1 -1
- package/dist/{pegDiagram-XKGWAZYB-DjP6v_UE.js → pegDiagram-XKGWAZYB-DTWrE0S4.js} +2 -2
- package/dist/{pencil-YvDg98Vt.js → pencil-weySvN0N.js} +1 -1
- package/dist/{pieDiagram-E7YTZNPT-Cq2pOY9y.js → pieDiagram-E7YTZNPT-COME2oGN.js} +1 -1
- package/dist/{process-output-BA7BGk1s.js → process-output-DNxpsd4n.js} +4 -4
- package/dist/{railroadDiagram-O6MQD6OU-BgTlJnKs.js → railroadDiagram-O6MQD6OU-CUeFcNTY.js} +2 -2
- package/dist/{requirementDiagram-BXWQKSXE-ZJoJ9EfE.js → requirementDiagram-BXWQKSXE-BUR4lDZG.js} +1 -1
- package/dist/{reveal-component-CfyL5u-u.js → reveal-component-BYskmwso.js} +8 -8
- package/dist/{select-BoGBoXrZ.js → select-Ca-POp4c.js} +4 -4
- package/dist/{sequenceDiagram-WJ2MYXX4-BJvdtgI2.js → sequenceDiagram-WJ2MYXX4-CSPmml3q.js} +1 -1
- package/dist/{spec-C7YYRfV5.js → spec-BgSMwzks.js} +4 -4
- package/dist/{stateDiagram-D77RDMKH-UBhd6uK-.js → stateDiagram-D77RDMKH-BDUC8Pi9.js} +2 -2
- package/dist/{stateDiagram-v2-MP3YSRHH-Cx2Xr13h.js → stateDiagram-v2-MP3YSRHH-BH-qyk8a.js} +2 -2
- package/dist/{static-state-Dn05_alZ.js → static-state-Cqzv5X7B.js} +1 -1
- package/dist/{swimlanes-42K2YHIH-uVbva14y.js → swimlanes-42K2YHIH-CLE9Kiir.js} +1 -1
- package/dist/{swimlanesDiagram-VR7AAH4N-D2gn-4Ks.js → swimlanesDiagram-VR7AAH4N-Cv8kWAeA.js} +2 -2
- package/dist/{timeline-definition-24CTP7MA-DmIHJmrk.js → timeline-definition-24CTP7MA-fbRGX21i.js} +1 -1
- package/dist/{toast-CXcT9TJm.js → toast-0xspcdmv.js} +3 -3
- package/dist/{tooltip-DbRnGlK2.js → tooltip-BwlFTaNy.js} +1 -1
- package/dist/{use-restore-focus-hhbpbJwV.js → use-restore-focus-fKgXR0nb.js} +1 -1
- package/dist/{useDateFormatter-BhUfu7Zv.js → useDateFormatter-B7LvPmsw.js} +2 -2
- package/dist/{useDeepCompareMemoize-Crc0VFdZ.js → useDeepCompareMemoize-OhBYt-q2.js} +1 -1
- package/dist/{useLifecycle-BCXa5UQv.js → useLifecycle-D9xcFAIN.js} +1 -1
- package/dist/{vega-component-DqWRZerK.js → vega-component-Chak9Aon.js} +6 -6
- package/dist/{vennDiagram-4TSXK5OY-BYps24XX.js → vennDiagram-4TSXK5OY-BzKtg8gL.js} +1 -1
- package/dist/{wardleyDiagram-VM6X3IG4-eJTaJjCK.js → wardleyDiagram-VM6X3IG4-R0SgDvz1.js} +1 -1
- package/dist/{xychartDiagram-S5SC5T6Z-DUHbPn-K.js → xychartDiagram-S5SC5T6Z-DRskTHEM.js} +1 -1
- package/package.json +1 -1
- package/src/__mocks__/document.tsx +1 -0
- package/src/__mocks__/executions.ts +3 -1
- package/src/components/editor/actions/__tests__/name-cell-input.test.tsx +1 -0
- package/src/components/editor/actions/__tests__/useCellActionButton.test.tsx +1 -0
- package/src/components/editor/chrome/wrapper/__tests__/document-sync-status.test.tsx +3 -1
- package/src/core/cells/__tests__/flush-document.test.ts +3 -1
- package/src/core/config/__tests__/app-config.test.ts +1 -1
- package/src/core/executions/atoms.ts +2 -2
- package/src/core/islands/bootstrap.ts +1 -0
- package/src/core/meta/__tests__/code-visibility.test.tsx +1 -1
- package/src/core/notebook/document/__tests__/codemirror.test.ts +1 -0
- package/src/core/notebook/document/__tests__/hooks.test.tsx +1 -0
- package/src/core/notebook/document/__tests__/model.test.ts +6 -1
- package/src/core/notebook/document/__tests__/scenario-fixture.ts +1 -0
- package/src/core/notebook/document/__tests__/scenarios.test.ts +61 -0
- package/src/core/notebook/document/__tests__/state.test.ts +1 -0
- package/src/core/notebook/document/__tests__/submission.test.ts +1 -0
- package/src/core/notebook/document/__tests__/test-notebook.ts +14 -2
- package/src/core/notebook/document/model.ts +6 -3
- package/src/core/notebook/document/state.ts +38 -15
- package/src/core/notebook/replica/__tests__/document.test.ts +12 -7
- package/src/core/notebook/replica/__tests__/replica.test.ts +69 -5
- package/src/core/notebook/replica/replica.ts +71 -24
- package/src/core/notebook/replica/resources/document.ts +1 -1
- package/src/core/saving/__tests__/state.test.ts +1 -1
- package/src/core/session/active-notebook.ts +5 -4
- package/src/core/session/useNotebookSession.tsx +1 -0
- package/src/core/transports/__tests__/server.test.ts +5 -1
|
@@ -167,17 +167,55 @@ describe("NotebookReplica lifetime", () => {
|
|
|
167
167
|
const second = await opened();
|
|
168
168
|
expect(second.cursor).toBe("97");
|
|
169
169
|
second.receive({ event: "reset", data: {} });
|
|
170
|
+
// What was on show stays until the snapshot that replaces it is ready.
|
|
171
|
+
const replacement = fixtureMessages("notebook-events.sse").map((event) =>
|
|
172
|
+
JSON.parse(JSON.stringify(event).replaceAll('"n1"', '"n2"')),
|
|
173
|
+
);
|
|
174
|
+
const ready = fixtureEvents("notebook-events.sse").findIndex(
|
|
175
|
+
(event) => event.event === "ready",
|
|
176
|
+
);
|
|
177
|
+
replacement.slice(0, ready).forEach(second.receive);
|
|
170
178
|
expect(store.get(client.documentAtom)).toBeNull();
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
179
|
+
expect(store.get(client.shownDocumentAtom)?.revision.notebook_id).toBe(
|
|
180
|
+
"n1",
|
|
181
|
+
);
|
|
182
|
+
replacement.slice(ready).forEach(second.receive);
|
|
176
183
|
expect(store.get(client.documentAtom)?.revision.notebook_id).toBe("n2");
|
|
184
|
+
expect(store.get(client.shownDocumentAtom)).toBe(
|
|
185
|
+
store.get(client.documentAtom),
|
|
186
|
+
);
|
|
177
187
|
expect(store.get(client.connectionAtom).state).toBe(ConnectionState.OPEN);
|
|
178
188
|
expect(store.get(client.notebookAtom)?.id).toBe("n2");
|
|
179
189
|
});
|
|
180
190
|
|
|
191
|
+
it("keeps what is on show when the snapshot replacing it is interrupted", async () => {
|
|
192
|
+
vi.useFakeTimers();
|
|
193
|
+
const { connect, opened, client, store } = setup();
|
|
194
|
+
connect(lifetime().signal);
|
|
195
|
+
const first = await opened();
|
|
196
|
+
fixtureMessages("notebook-events.sse").forEach(first.receive);
|
|
197
|
+
const replacement = fixtureMessages("notebook-events.sse").map((event) =>
|
|
198
|
+
JSON.parse(JSON.stringify(event).replaceAll('"n1"', '"n2"')),
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
first.receive({ event: "reset", data: {} });
|
|
202
|
+
replacement.slice(0, 3).forEach(first.receive);
|
|
203
|
+
first.drop();
|
|
204
|
+
await backoff();
|
|
205
|
+
expect(store.get(client.documentAtom)).toBeNull();
|
|
206
|
+
expect(store.get(client.shownDocumentAtom)?.revision.notebook_id).toBe(
|
|
207
|
+
"n1",
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
// The partial snapshot cannot be resumed, so the stream starts over.
|
|
211
|
+
const second = await opened();
|
|
212
|
+
expect(second.cursor).toBeNull();
|
|
213
|
+
second.receive({ event: "reset", data: {} });
|
|
214
|
+
replacement.forEach(second.receive);
|
|
215
|
+
expect(store.get(client.documentAtom)?.revision.notebook_id).toBe("n2");
|
|
216
|
+
expect(store.get(client.notebookAtom)?.id).toBe("n2");
|
|
217
|
+
});
|
|
218
|
+
|
|
181
219
|
it.each([
|
|
182
220
|
["a message that is not an event", "{broken"],
|
|
183
221
|
["an event from another notebook", "identity"],
|
|
@@ -516,6 +554,32 @@ describe("NotebookReplica attachments", () => {
|
|
|
516
554
|
},
|
|
517
555
|
);
|
|
518
556
|
|
|
557
|
+
it("keeps presence hidden across a second disconnect until an empty replay is ready", async () => {
|
|
558
|
+
vi.useFakeTimers();
|
|
559
|
+
const { client, store, attempt, opened } = await open();
|
|
560
|
+
fixtureMessages("notebook-events.sse").forEach(attempt.receive);
|
|
561
|
+
const confirmed = store.get(client.documentAtom);
|
|
562
|
+
attempt.drop();
|
|
563
|
+
await backoff();
|
|
564
|
+
const replay = await opened();
|
|
565
|
+
replay.receive({
|
|
566
|
+
event: "attachment.removed",
|
|
567
|
+
id: "98",
|
|
568
|
+
data: { id: browser.id },
|
|
569
|
+
});
|
|
570
|
+
expect(store.get(client.attachmentsAtom)).toEqual([]);
|
|
571
|
+
replay.drop();
|
|
572
|
+
await backoff();
|
|
573
|
+
const resumed = await opened();
|
|
574
|
+
expect(resumed.cursor).toBe("98");
|
|
575
|
+
expect(store.get(client.documentAtom)).toBe(confirmed);
|
|
576
|
+
expect(store.get(client.attachmentsAtom)).toEqual([]);
|
|
577
|
+
expect(store.get(client.notebookAtom)).toBeNull();
|
|
578
|
+
resumed.receive({ event: "ready", id: "98", data: {} });
|
|
579
|
+
expect(store.get(client.attachmentsAtom)).toEqual([agent]);
|
|
580
|
+
expect(store.get(client.notebookAtom)?.id).toBe("n1");
|
|
581
|
+
});
|
|
582
|
+
|
|
519
583
|
it.each(["drop", "stop", "removed", "abort"])(
|
|
520
584
|
"clears presence on %s and ignores messages after disposal",
|
|
521
585
|
async (reason) => {
|
|
@@ -59,13 +59,21 @@ export interface NotebookReplica {
|
|
|
59
59
|
/** Identity and capabilities, available while the stream is connected and ready. */
|
|
60
60
|
readonly notebookAtom: Atom<NotebookOutput | null>;
|
|
61
61
|
/**
|
|
62
|
-
* The
|
|
62
|
+
* The document the current stream has confirmed.
|
|
63
63
|
*
|
|
64
64
|
* Null until a snapshot is complete, after reset or removal, and on
|
|
65
65
|
* connections without host document events. A temporary disconnection
|
|
66
|
-
* retains the last document. Partial updates are not exposed.
|
|
66
|
+
* retains the last document. Partial updates are not exposed. Edits
|
|
67
|
+
* submit against this one.
|
|
67
68
|
*/
|
|
68
69
|
readonly documentAtom: Atom<Document | null>;
|
|
70
|
+
/**
|
|
71
|
+
* The document on show: `documentAtom`, or through a reset, the one it
|
|
72
|
+
* replaced until the snapshot that follows is complete.
|
|
73
|
+
*
|
|
74
|
+
* For display only. Nothing confirms it still describes the host.
|
|
75
|
+
*/
|
|
76
|
+
readonly shownDocumentAtom: Atom<Document | null>;
|
|
69
77
|
/**
|
|
70
78
|
* The backend this replica follows, or null while not connected.
|
|
71
79
|
*
|
|
@@ -81,12 +89,15 @@ export interface NotebookReplica {
|
|
|
81
89
|
* Runs and executions as the stream reports them.
|
|
82
90
|
*
|
|
83
91
|
* Visible as events arrive, including during a snapshot, so a consumer
|
|
84
|
-
* joins with `
|
|
85
|
-
* Kept across a temporary disconnection
|
|
86
|
-
*
|
|
92
|
+
* joins with `shownDocumentAtom`, which is null until the snapshot is
|
|
93
|
+
* ready. Kept across a temporary disconnection and shown through a
|
|
94
|
+
* reset, like the document, and cleared on removal.
|
|
87
95
|
*/
|
|
88
96
|
readonly executionsAtom: Atom<Executions>;
|
|
89
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* Each document cell's last completed execution record, kept while it
|
|
99
|
+
* runs again and shown through a reset.
|
|
100
|
+
*/
|
|
90
101
|
readonly resultsAtom: Atom<Results>;
|
|
91
102
|
/**
|
|
92
103
|
* Follow a backend, replacing any current connection.
|
|
@@ -153,12 +164,28 @@ export function createNotebookReplica(
|
|
|
153
164
|
executions,
|
|
154
165
|
results,
|
|
155
166
|
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
167
|
+
type Stream = typeof reducer.initial;
|
|
168
|
+
/**
|
|
169
|
+
* The stream as the host reports it, and what it showed before it
|
|
170
|
+
* restarted, until the snapshot that replaces it is complete.
|
|
171
|
+
*
|
|
172
|
+
* A host resets a stream it cannot resume, and a transport restarts one
|
|
173
|
+
* whose session changed. Showing the new snapshot as it arrives would
|
|
174
|
+
* empty every view for as long as that takes.
|
|
175
|
+
*/
|
|
176
|
+
const followedAtom = atom<{ stream: Stream; retained: Stream | null }>({
|
|
177
|
+
stream: reducer.initial,
|
|
178
|
+
retained: null,
|
|
179
|
+
});
|
|
180
|
+
const streamAtom = atom((get) => get(followedAtom).stream);
|
|
181
|
+
const shownAtom = atom((get) => {
|
|
182
|
+
const { stream, retained } = get(followedAtom);
|
|
183
|
+
return retained ?? stream;
|
|
184
|
+
});
|
|
159
185
|
const presentAtom = atom(
|
|
160
186
|
(get) =>
|
|
161
|
-
get(
|
|
187
|
+
get(streamAtom).phase === "live" &&
|
|
188
|
+
get(connectionAtom).state === ConnectionState.OPEN,
|
|
162
189
|
);
|
|
163
190
|
const notebookAtom = atom((get) =>
|
|
164
191
|
get(presentAtom) ? get(streamAtom).notebook : null,
|
|
@@ -166,6 +193,9 @@ export function createNotebookReplica(
|
|
|
166
193
|
const documentAtom = atom(
|
|
167
194
|
(get) => get(streamAtom).resources.document.current,
|
|
168
195
|
);
|
|
196
|
+
const shownDocumentAtom = atom(
|
|
197
|
+
(get) => get(shownAtom).resources.document.current,
|
|
198
|
+
);
|
|
169
199
|
const attachmentsAtom = atom((get) =>
|
|
170
200
|
get(presentAtom)
|
|
171
201
|
? get(streamAtom).resources.attachments
|
|
@@ -174,20 +204,39 @@ export function createNotebookReplica(
|
|
|
174
204
|
const runtimeAtom = atom((get) =>
|
|
175
205
|
get(presentAtom) ? get(streamAtom).resources.runtime : null,
|
|
176
206
|
);
|
|
177
|
-
const executionsAtom = atom((get) => get(
|
|
178
|
-
const resultsAtom = atom((get) => get(
|
|
207
|
+
const executionsAtom = atom((get) => get(shownAtom).resources.executions);
|
|
208
|
+
const resultsAtom = atom((get) => get(shownAtom).resources.results);
|
|
179
209
|
const backendAtom = atom<NotebookBackend | null>(null);
|
|
180
210
|
/** The connection this replica follows. Connecting again ends it. */
|
|
181
211
|
let current: { end(): void; reconnect(): Promise<void> } | undefined;
|
|
182
212
|
|
|
213
|
+
/** Retain what a restart replaces until its snapshot is complete. */
|
|
214
|
+
function setStream(next: Stream) {
|
|
215
|
+
store.set(followedAtom, (followed) => {
|
|
216
|
+
const { stream, retained } = followed;
|
|
217
|
+
if (next === stream) {
|
|
218
|
+
return followed;
|
|
219
|
+
}
|
|
220
|
+
if (next.phase !== "snapshot") {
|
|
221
|
+
return { stream: next, retained: null };
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
stream: next,
|
|
225
|
+
retained: stream.phase === "snapshot" ? retained : stream,
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
183
230
|
function setStatus(status: ConnectionStatus) {
|
|
184
|
-
|
|
231
|
+
if (status.state === ConnectionState.CONNECTING) {
|
|
232
|
+
setStream(reducer.resume(store.get(streamAtom)));
|
|
233
|
+
}
|
|
185
234
|
store.set(connectionAtom, status);
|
|
186
235
|
}
|
|
187
236
|
|
|
188
237
|
/** Drop what the stream reported and show `status`. */
|
|
189
238
|
function clear(status: ConnectionStatus) {
|
|
190
|
-
store.set(
|
|
239
|
+
store.set(followedAtom, { stream: reducer.initial, retained: null });
|
|
191
240
|
setStatus(status);
|
|
192
241
|
}
|
|
193
242
|
|
|
@@ -195,6 +244,7 @@ export function createNotebookReplica(
|
|
|
195
244
|
connectionAtom,
|
|
196
245
|
notebookAtom,
|
|
197
246
|
documentAtom,
|
|
247
|
+
shownDocumentAtom,
|
|
198
248
|
backendAtom,
|
|
199
249
|
attachmentsAtom,
|
|
200
250
|
runtimeAtom,
|
|
@@ -216,15 +266,12 @@ export function createNotebookReplica(
|
|
|
216
266
|
const { transport } = connected;
|
|
217
267
|
let events: NotebookEvents<(typeof TYPES)[number]> | undefined;
|
|
218
268
|
let checkingHealth = false;
|
|
219
|
-
// Whether the replica still holds the state the last cursor describes.
|
|
220
|
-
let resumable = true;
|
|
221
269
|
|
|
222
270
|
/** Mirror one stream into the atoms until it closes. */
|
|
223
271
|
function follow(cursor?: string) {
|
|
224
272
|
if (cursor === undefined) {
|
|
225
|
-
|
|
273
|
+
setStream(reducer.initial);
|
|
226
274
|
}
|
|
227
|
-
resumable = true;
|
|
228
275
|
const current = new NotebookEvents(transport, {
|
|
229
276
|
types: TYPES,
|
|
230
277
|
cursor,
|
|
@@ -260,7 +307,6 @@ export function createNotebookReplica(
|
|
|
260
307
|
function stopMalformed(source: NotebookEvents<string>) {
|
|
261
308
|
source.close();
|
|
262
309
|
// The cursor can already include an event the replica rejected.
|
|
263
|
-
resumable = false;
|
|
264
310
|
clear(malformed);
|
|
265
311
|
}
|
|
266
312
|
|
|
@@ -276,16 +322,13 @@ export function createNotebookReplica(
|
|
|
276
322
|
return;
|
|
277
323
|
}
|
|
278
324
|
try {
|
|
279
|
-
|
|
325
|
+
setStream(reducer.reduce(store.get(streamAtom), event));
|
|
280
326
|
} catch (error) {
|
|
281
327
|
// An event the replica cannot apply, such as another notebook's.
|
|
282
328
|
Logger.error("Failed to apply notebook event", error);
|
|
283
329
|
stopMalformed(source);
|
|
284
330
|
return;
|
|
285
331
|
}
|
|
286
|
-
if (event.event === "ready" || event.event === "reset") {
|
|
287
|
-
store.set(readyAtom, event.event === "ready");
|
|
288
|
-
}
|
|
289
332
|
}
|
|
290
333
|
|
|
291
334
|
const reconnect = async () => {
|
|
@@ -303,7 +346,11 @@ export function createNotebookReplica(
|
|
|
303
346
|
setStatus(disconnected);
|
|
304
347
|
return;
|
|
305
348
|
}
|
|
306
|
-
follow(
|
|
349
|
+
follow(
|
|
350
|
+
store.get(streamAtom).phase === "snapshot"
|
|
351
|
+
? undefined
|
|
352
|
+
: (events.cursor ?? undefined),
|
|
353
|
+
);
|
|
307
354
|
} catch (error) {
|
|
308
355
|
if (!signal.aborted) {
|
|
309
356
|
Logger.error("Notebook health check failed", error);
|
|
@@ -90,7 +90,7 @@ export const document: NotebookResource<DocumentState, "cell" | "document"> = {
|
|
|
90
90
|
if (state.pending === null) {
|
|
91
91
|
return state;
|
|
92
92
|
}
|
|
93
|
-
if (phase
|
|
93
|
+
if (phase !== "snapshot") {
|
|
94
94
|
throw new Error("Stream ended with an incomplete document update");
|
|
95
95
|
}
|
|
96
96
|
return state.pending.revision === null
|
|
@@ -39,7 +39,7 @@ function connect(
|
|
|
39
39
|
) {
|
|
40
40
|
store.set(
|
|
41
41
|
activeNotebookReplicaAtom,
|
|
42
|
-
partial<NotebookReplica>({
|
|
42
|
+
partial<NotebookReplica>({ shownDocumentAtom: atom(document) }, "replica"),
|
|
43
43
|
);
|
|
44
44
|
store.set(
|
|
45
45
|
activeDocumentModelAtom,
|
|
@@ -18,11 +18,12 @@ export const activeNotebookBackendAtom = atom((get) => {
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* The document the host last confirmed, or null while no notebook is
|
|
21
|
-
* connected.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* connected. Through a reset it is the document the reset replaced. Facts
|
|
22
|
+
* the host owns read this one, such as permission, the app config, saved
|
|
23
|
+
* state and whether source is available. What the user is editing reads
|
|
24
|
+
* the model's document, which adds this browser's drafts.
|
|
24
25
|
*/
|
|
25
26
|
export const confirmedDocumentAtom = atom((get) => {
|
|
26
27
|
const replica = get(activeNotebookReplicaAtom);
|
|
27
|
-
return replica === null ? null : get(replica.
|
|
28
|
+
return replica === null ? null : get(replica.shownDocumentAtom);
|
|
28
29
|
});
|
|
@@ -292,7 +292,7 @@ describe.each(["websocket", "sse"] as const)(
|
|
|
292
292
|
: "http://localhost/sse";
|
|
293
293
|
|
|
294
294
|
it.each(["automatic", "manual"])(
|
|
295
|
-
"discards the cursor and
|
|
295
|
+
"discards the cursor and waits for the new session's snapshot on %s reconnect",
|
|
296
296
|
async (recovery) => {
|
|
297
297
|
vi.useFakeTimers();
|
|
298
298
|
let target = `${base}?session_id=s1`;
|
|
@@ -323,15 +323,19 @@ describe.each(["websocket", "sse"] as const)(
|
|
|
323
323
|
await client.reconnect();
|
|
324
324
|
}
|
|
325
325
|
const second = await connection.opened();
|
|
326
|
+
// The earlier session's document stays on show, but nothing edits
|
|
327
|
+
// against it and nothing says the notebook is ready.
|
|
326
328
|
expect({
|
|
327
329
|
cursor: second.cursor,
|
|
328
330
|
notebook: store.get(client.notebookAtom),
|
|
329
331
|
document: store.get(client.documentAtom),
|
|
332
|
+
shown: store.get(client.shownDocumentAtom)?.revision.notebook_id,
|
|
330
333
|
attachments: store.get(client.attachmentsAtom),
|
|
331
334
|
}).toEqual({
|
|
332
335
|
cursor: null,
|
|
333
336
|
notebook: null,
|
|
334
337
|
document: null,
|
|
338
|
+
shown: "n1",
|
|
335
339
|
attachments: [],
|
|
336
340
|
});
|
|
337
341
|
|