@tangle-network/ui 11.5.0 → 11.6.0

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.
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  DocumentEditorPane
4
- } from "./chunk-NZLLDHEG.js";
4
+ } from "./chunk-QGTIBEPX.js";
5
5
  import "./chunk-Q56BYXQF.js";
6
6
  import "./chunk-LTEKI7YJ.js";
7
7
  import "./chunk-P5F43A65.js";
@@ -2,7 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
3
  import { a as ArtifactPaneProps } from './artifact-pane-DpuWcAiF.js';
4
4
  import { HocuspocusProvider } from '@hocuspocus/provider';
5
- import * as Y from 'yjs';
5
+ import * as Yjs from 'yjs';
6
6
 
7
7
  /**
8
8
  * Connection state for the Hocuspocus provider.
@@ -24,7 +24,7 @@ interface Collaborator {
24
24
  */
25
25
  interface EditorContextValue {
26
26
  /** The Y.Doc instance for collaboration */
27
- doc: Y.Doc;
27
+ doc: Yjs.Doc;
28
28
  /** The Hocuspocus provider instance */
29
29
  provider: HocuspocusProvider | null;
30
30
  /** Current connection state */
@@ -83,9 +83,13 @@ interface EditorProviderProps {
83
83
  }
84
84
  /**
85
85
  * EditorProvider wraps children with Hocuspocus collaboration context.
86
- * Manages WebSocket connection, Y.Doc, and awareness state.
86
+ * Manages WebSocket connection, Y.Doc, and awareness state. Loads `yjs` and
87
+ * `@hocuspocus/provider` — and no tiptap package — before it renders children,
88
+ * because every child hook reads a context that only the loaded provider can
89
+ * supply. A consumer that drives its own editor from that context therefore
90
+ * needs those two peers alone.
87
91
  */
88
- declare function EditorProvider({ websocketUrl, documentName, token, tokenExpiresAt, user, autoConnect, autoReconnect, maxReconnectAttempts, onConnectionChange, onSync, onAuthError, onRefreshToken, children, }: EditorProviderProps): react_jsx_runtime.JSX.Element;
92
+ declare function EditorProvider(props: EditorProviderProps): react_jsx_runtime.JSX.Element;
89
93
  /**
90
94
  * Hook to access the editor context.
91
95
  * Must be used within an EditorProvider.
package/dist/editor.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as Collaborator, a as ConnectionState } from './document-editor-pane-C3cYEDWZ.js';
2
- export { D as DocumentEditorBackend, b as DocumentEditorMode, c as DocumentEditorPane, d as DocumentEditorPaneCollaborationConfig, e as DocumentEditorPaneProps, E as EditorContextValue, f as EditorProvider, g as EditorProviderProps, h as EditorTokenRefreshResult, i as EditorUser, u as useEditorContext } from './document-editor-pane-C3cYEDWZ.js';
1
+ import { C as Collaborator, a as ConnectionState } from './document-editor-pane-IAEQn_Dl.js';
2
+ export { D as DocumentEditorBackend, b as DocumentEditorMode, c as DocumentEditorPane, d as DocumentEditorPaneCollaborationConfig, e as DocumentEditorPaneProps, E as EditorContextValue, f as EditorProvider, g as EditorProviderProps, h as EditorTokenRefreshResult, i as EditorUser, u as useEditorContext } from './document-editor-pane-IAEQn_Dl.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { Editor } from '@tiptap/react';
5
5
  import { HocuspocusProvider } from '@hocuspocus/provider';
@@ -41,9 +41,10 @@ interface TiptapEditorProps {
41
41
  }
42
42
  /**
43
43
  * TiptapEditor - Collaborative markdown editor with Y.js sync.
44
- * Must be used within an EditorProvider.
44
+ * Must be used within an EditorProvider. Loads its tiptap, Hocuspocus and
45
+ * yjs peers on first render.
45
46
  */
46
- declare function TiptapEditor({ initialContent, placeholder, readOnly, autoFocus, className, contentClassName, onUpdate, onSelectionUpdate, onReady, }: TiptapEditorProps): react_jsx_runtime.JSX.Element;
47
+ declare function TiptapEditor(props: TiptapEditorProps): react_jsx_runtime.JSX.Element;
47
48
  /**
48
49
  * Collaborators list component.
49
50
  * Shows active users in the document.
package/dist/editor.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  useEditorConnection,
12
12
  useEditorContext,
13
13
  useYjsState
14
- } from "./chunk-NZLLDHEG.js";
14
+ } from "./chunk-QGTIBEPX.js";
15
15
  import "./chunk-Q56BYXQF.js";
16
16
  import "./chunk-LTEKI7YJ.js";
17
17
  import "./chunk-P5F43A65.js";
package/dist/files.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { GitStatusEntry, ContextMenuItem, ContextMenuOpenContext, GitStatus } from '@pierre/trees';
3
3
  import { ReactNode, CSSProperties } from 'react';
4
- import { b as DocumentEditorMode, D as DocumentEditorBackend, d as DocumentEditorPaneCollaborationConfig } from './document-editor-pane-C3cYEDWZ.js';
4
+ import { b as DocumentEditorMode, D as DocumentEditorBackend, d as DocumentEditorPaneCollaborationConfig } from './document-editor-pane-IAEQn_Dl.js';
5
5
  import { a as ArtifactPaneProps } from './artifact-pane-DpuWcAiF.js';
6
6
  import '@hocuspocus/provider';
7
7
  import 'yjs';
package/dist/files.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  FileTree,
6
6
  RichFileTree,
7
7
  filterFileTree
8
- } from "./chunk-7O22XQ4D.js";
8
+ } from "./chunk-PLWRAS5Z.js";
9
9
  import {
10
10
  detectFileFormat,
11
11
  fileExtension,
package/dist/index.d.ts CHANGED
@@ -35,7 +35,7 @@ import '@radix-ui/react-progress';
35
35
  import '@radix-ui/react-switch';
36
36
  import '@radix-ui/react-label';
37
37
  import '@pierre/trees';
38
- import './document-editor-pane-C3cYEDWZ.js';
38
+ import './document-editor-pane-IAEQn_Dl.js';
39
39
  import '@hocuspocus/provider';
40
40
  import 'yjs';
41
41
  import 'nanostores';
package/dist/index.js CHANGED
@@ -221,7 +221,7 @@ import {
221
221
  FileTree,
222
222
  RichFileTree,
223
223
  filterFileTree
224
- } from "./chunk-7O22XQ4D.js";
224
+ } from "./chunk-PLWRAS5Z.js";
225
225
  import {
226
226
  detectFileFormat,
227
227
  fileExtension,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/ui",
3
- "version": "11.5.0",
3
+ "version": "11.6.0",
4
4
  "description": "Generic React UI components for Tangle products — primitives, chat, run, files, editor, markdown.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -0,0 +1,58 @@
1
+ import { render, screen, waitFor } from "@testing-library/react";
2
+ import { afterEach, describe, expect, it, vi } from "vitest";
3
+ import type * as EditorPeers from "./editor-peers";
4
+
5
+ const markdown = "# Release notes\n\nThe editor loads on demand.";
6
+
7
+ afterEach(() => {
8
+ vi.resetModules();
9
+ });
10
+
11
+ /** Loads the pane with every peer loader rejecting, as for a consumer that
12
+ * installed neither tiptap nor the collaboration stack. The spies report
13
+ * whether a render reached a loader at all. */
14
+ async function paneWithoutPeers(message: string) {
15
+ const loaders = {
16
+ loadDocumentEditorPeers: vi.fn(async () => {
17
+ throw new Error(message);
18
+ }),
19
+ loadCollaborationPeers: vi.fn(async () => {
20
+ throw new Error(message);
21
+ }),
22
+ loadEditorProviderPeers: vi.fn(async () => {
23
+ throw new Error(message);
24
+ }),
25
+ };
26
+ vi.resetModules();
27
+ vi.doMock("./editor-peers", async () => ({
28
+ ...(await vi.importActual<typeof EditorPeers>("./editor-peers")),
29
+ ...loaders,
30
+ }));
31
+ const { DocumentEditorPane } = await import("./document-editor-pane");
32
+ return { DocumentEditorPane, loaders };
33
+ }
34
+
35
+ describe("DocumentEditorPane without the editor peers", () => {
36
+ it("renders the preview, because only the edit tab needs the peers", async () => {
37
+ const { DocumentEditorPane, loaders } = await paneWithoutPeers(
38
+ "peers are not installed",
39
+ );
40
+
41
+ render(<DocumentEditorPane title="Notes" markdown={markdown} />);
42
+
43
+ // The promise this pane's editors carry is exactly this: a consumer that
44
+ // never opens the edit tab pays nothing for tiptap.
45
+ expect(screen.getByText("Release notes")).toBeInTheDocument();
46
+ expect(screen.getByText("The editor loads on demand.")).toBeInTheDocument();
47
+ expect(screen.getByRole("tab", { name: "Edit" })).toBeInTheDocument();
48
+
49
+ // Reaching no loader is the claim. Asserting only that the placeholder is
50
+ // absent would also pass for a pane that rendered nothing at all.
51
+ await waitFor(() => {
52
+ expect(screen.queryByText("Loading editor…")).toBeNull();
53
+ });
54
+ expect(loaders.loadDocumentEditorPeers).not.toHaveBeenCalled();
55
+ expect(loaders.loadCollaborationPeers).not.toHaveBeenCalled();
56
+ expect(loaders.loadEditorProviderPeers).not.toHaveBeenCalled();
57
+ });
58
+ });
@@ -0,0 +1,102 @@
1
+ import { fireEvent, render, screen } from "@testing-library/react";
2
+ import { Component, type ReactNode, Suspense } from "react";
3
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4
+ import { retryableLazyEditor } from "./editor-lazy";
5
+ import { MissingEditorPeersError } from "./editor-peers";
6
+
7
+ /** Catches the rejection the lazy component throws, and can mount it again. */
8
+ class ResettableBoundary extends Component<
9
+ { children: ReactNode },
10
+ { failure: Error | null }
11
+ > {
12
+ state = { failure: null as Error | null };
13
+
14
+ static getDerivedStateFromError(error: Error) {
15
+ return { failure: error };
16
+ }
17
+
18
+ render() {
19
+ if (this.state.failure) {
20
+ return (
21
+ <button type="button" onClick={() => this.setState({ failure: null })}>
22
+ failed: {this.state.failure.message}
23
+ </button>
24
+ );
25
+ }
26
+ return this.props.children;
27
+ }
28
+ }
29
+
30
+ function Loaded() {
31
+ return <span>editor</span>;
32
+ }
33
+
34
+ /** React reports a caught render error on the console; the assertions read it. */
35
+ let consoleError: ReturnType<typeof vi.spyOn>;
36
+
37
+ beforeEach(() => {
38
+ consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
39
+ });
40
+
41
+ afterEach(() => {
42
+ consoleError.mockRestore();
43
+ });
44
+
45
+ function renderRetryable(load: () => Promise<typeof Loaded>) {
46
+ const lazyEditor = retryableLazyEditor(load);
47
+ function Host() {
48
+ const LazyEditor = lazyEditor();
49
+ return (
50
+ <Suspense fallback={<span>loading</span>}>
51
+ <LazyEditor />
52
+ </Suspense>
53
+ );
54
+ }
55
+ return render(
56
+ <ResettableBoundary>
57
+ <Host />
58
+ </ResettableBoundary>,
59
+ );
60
+ }
61
+
62
+ describe("retryableLazyEditor", () => {
63
+ it("re-attempts the load after a transient failure", async () => {
64
+ // `lazy` caches its first rejection for the life of the component, so one
65
+ // failed chunk fetch would otherwise hold the editor broken until a full
66
+ // page reload.
67
+ const load = vi
68
+ .fn<() => Promise<typeof Loaded>>()
69
+ .mockRejectedValueOnce(new Error("Failed to fetch dynamically imported module"))
70
+ .mockResolvedValue(Loaded);
71
+
72
+ renderRetryable(load);
73
+
74
+ const retry = await screen.findByRole("button");
75
+ expect(retry).toHaveTextContent("Failed to fetch dynamically imported module");
76
+ expect(load).toHaveBeenCalledTimes(1);
77
+
78
+ fireEvent.click(retry);
79
+
80
+ expect(await screen.findByText("editor")).toBeInTheDocument();
81
+ expect(load).toHaveBeenCalledTimes(2);
82
+ });
83
+
84
+ it("keeps a missing peer permanent, so a remount does not import it again", async () => {
85
+ // A package does not install itself mid-session. Retrying would only
86
+ // repeat the same failure and hide the install list behind a loop.
87
+ const load = vi
88
+ .fn<() => Promise<typeof Loaded>>()
89
+ .mockRejectedValue(new MissingEditorPeersError("Install @tiptap/react."));
90
+
91
+ renderRetryable(load);
92
+
93
+ const retry = await screen.findByRole("button");
94
+ expect(retry).toHaveTextContent("Install @tiptap/react.");
95
+ expect(load).toHaveBeenCalledTimes(1);
96
+
97
+ fireEvent.click(retry);
98
+
99
+ expect(await screen.findByRole("button")).toHaveTextContent("Install @tiptap/react.");
100
+ expect(load).toHaveBeenCalledTimes(1);
101
+ });
102
+ });
@@ -0,0 +1,40 @@
1
+ import { type ComponentType, lazy, type LazyExoticComponent } from "react";
2
+ import { isMissingEditorPeersError } from "./editor-peers";
3
+
4
+ /**
5
+ * Builds a `lazy` editor component that a remount can re-attempt.
6
+ *
7
+ * `lazy` caches its first rejection for the life of the component. That is
8
+ * right for a missing peer, which stays missing for the session, and wrong for
9
+ * a transient chunk fetch: one failed network request would otherwise hold the
10
+ * editor broken until a full page reload.
11
+ *
12
+ * The returned function gives the component to render, and a caller must call
13
+ * it on every render: a transient failure replaces the component, and a caller
14
+ * that holds the one it got earlier keeps replaying the cached rejection.
15
+ *
16
+ * A `MissingEditorPeersError` keeps the cached rejection, so the install list
17
+ * reaches the consumer's error boundary once and the loader does not run
18
+ * again. Any other rejection replaces the component, so the next mount — an
19
+ * error boundary that resets, or a remount by the parent — starts a fresh
20
+ * attempt.
21
+ */
22
+ export function retryableLazyEditor<P extends object>(
23
+ loadComponent: () => Promise<ComponentType<P>>,
24
+ ): () => LazyExoticComponent<ComponentType<P>> {
25
+ function build(): LazyExoticComponent<ComponentType<P>> {
26
+ return lazy(async () => {
27
+ try {
28
+ return { default: await loadComponent() };
29
+ } catch (error) {
30
+ if (!isMissingEditorPeersError(error)) {
31
+ current = build();
32
+ }
33
+ throw error;
34
+ }
35
+ });
36
+ }
37
+
38
+ let current = build();
39
+ return () => current;
40
+ }
@@ -0,0 +1,25 @@
1
+ "use client";
2
+
3
+ import { cn } from "../lib/utils";
4
+
5
+ /**
6
+ * Stands in for an editor while its optional peers load. The editors reach
7
+ * tiptap through a dynamic import, so an editor's first frame waits for that
8
+ * chunk. The live region announces the wait, which a screen reader has no
9
+ * other way to notice. Callers put their own minimum height first, so a
10
+ * caller-supplied className still wins.
11
+ */
12
+ export function EditorLoadingPlaceholder({ className }: { className?: string }) {
13
+ return (
14
+ <div
15
+ role="status"
16
+ aria-live="polite"
17
+ className={cn(
18
+ "flex w-full items-center justify-center rounded-lg border border-border border-dashed bg-muted text-muted-foreground text-sm",
19
+ className,
20
+ )}
21
+ >
22
+ Loading editor…
23
+ </div>
24
+ );
25
+ }
@@ -0,0 +1,250 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+ import {
3
+ asMissingEditorPeersError,
4
+ isMissingEditorPeersError,
5
+ isMissingPeerError,
6
+ } from "./editor-peers";
7
+
8
+ /** The namespace shape each peer has when it is installed. */
9
+ const installedPeers: Record<string, Record<string, unknown>> = {
10
+ "@tiptap/react": { useEditor: () => null, EditorContent: () => null },
11
+ "@tiptap/starter-kit": { default: { configure: () => ({}) } },
12
+ "@tiptap/extension-collaboration": { default: { configure: () => ({}) } },
13
+ "@tiptap/extension-collaboration-caret": { default: { configure: () => ({}) } },
14
+ "@hocuspocus/provider": { HocuspocusProvider: class {} },
15
+ yjs: { Doc: class {} },
16
+ };
17
+
18
+ /**
19
+ * Loads the module under test with the named peers replaced. The loaders read
20
+ * their peers through a dynamic import, so the substitution has to happen
21
+ * before the module graph is built — hence the reset and the dynamic import.
22
+ */
23
+ async function loadPeerLoaders(
24
+ replacements: Record<string, Record<string, unknown>> = {},
25
+ ) {
26
+ vi.resetModules();
27
+ for (const specifier of Object.keys(installedPeers)) {
28
+ const namespace = replacements[specifier] ?? installedPeers[specifier];
29
+ vi.doMock(specifier, () => namespace);
30
+ }
31
+ return await import("./editor-peers");
32
+ }
33
+
34
+ afterEach(() => {
35
+ vi.resetModules();
36
+ });
37
+
38
+ describe("isMissingPeerError", () => {
39
+ it("recognises what each bundler and runtime says for an uninstalled package", () => {
40
+ const messages = [
41
+ // Vite's stub for an optional peer that is not installed.
42
+ 'Could not resolve "@tiptap/react" imported by "@tangle-network/ui". Is it installed?',
43
+ // Node ESM.
44
+ "Cannot find package '@tiptap/react' imported from /app/index.js",
45
+ // CommonJS.
46
+ "Cannot find module '@tiptap/react'",
47
+ // webpack.
48
+ "Module not found: Error: Can't resolve '@tiptap/react' in '/app'",
49
+ // esbuild.
50
+ 'Failed to resolve entry for package "@tiptap/react"',
51
+ ];
52
+
53
+ for (const message of messages) {
54
+ expect(isMissingPeerError(new Error(message)), message).toBe(true);
55
+ }
56
+ });
57
+
58
+ it("leaves a transient chunk failure to report its own cause", () => {
59
+ // Enriching this one with "install the peers" sends the reader to the
60
+ // wrong fix, and the peers are already installed.
61
+ expect(
62
+ isMissingPeerError(new Error("Failed to fetch dynamically imported module")),
63
+ ).toBe(false);
64
+ expect(isMissingPeerError(new Error("Network request failed"))).toBe(false);
65
+ expect(isMissingPeerError("Could not resolve")).toBe(false);
66
+ });
67
+ });
68
+
69
+ describe("editor optional peer loaders", () => {
70
+ it("returns the namespaces the editors call", async () => {
71
+ const { loadCollaborationPeers, loadDocumentEditorPeers } = await loadPeerLoaders();
72
+
73
+ const documentPeers = await loadDocumentEditorPeers();
74
+ expect(documentPeers.react.useEditor).toBe(installedPeers["@tiptap/react"].useEditor);
75
+ expect(documentPeers.starterKit.default).toBe(
76
+ installedPeers["@tiptap/starter-kit"].default,
77
+ );
78
+
79
+ const collaborationPeers = await loadCollaborationPeers();
80
+ expect(collaborationPeers.hocuspocus.HocuspocusProvider).toBe(
81
+ installedPeers["@hocuspocus/provider"].HocuspocusProvider,
82
+ );
83
+ expect(collaborationPeers.yjs.Doc).toBe(installedPeers.yjs.Doc);
84
+ });
85
+
86
+ it("names the install list when a peer resolves to a namespace with no editor in it", async () => {
87
+ // A bundler can stub a missing optional peer as a silent empty namespace
88
+ // rather than a throwing module. That shape must still fail with the peers
89
+ // named, and not as an undefined-property crash in the middle of a render.
90
+ const { loadDocumentEditorPeers } = await loadPeerLoaders({
91
+ "@tiptap/starter-kit": { default: undefined },
92
+ });
93
+
94
+ await expect(loadDocumentEditorPeers()).rejects.toThrow(
95
+ /Install @tiptap\/react and @tiptap\/starter-kit/,
96
+ );
97
+ });
98
+
99
+ it("names the install list when an extension stub carries a default it cannot configure", async () => {
100
+ // The commonest stub shape is a default export that is present but empty.
101
+ // It passes a plain "is the default defined" test, and then the factory
102
+ // calls .configure() on it and throws an opaque TypeError mid-render.
103
+ const { loadDocumentEditorPeers } = await loadPeerLoaders({
104
+ "@tiptap/starter-kit": { default: {} },
105
+ });
106
+
107
+ await expect(loadDocumentEditorPeers()).rejects.toThrow(
108
+ /Install @tiptap\/react and @tiptap\/starter-kit/,
109
+ );
110
+ });
111
+
112
+ it.each([
113
+ "@tiptap/extension-collaboration",
114
+ "@tiptap/extension-collaboration-caret",
115
+ ])("names the collaboration install list when %s is an empty default", async (specifier) => {
116
+ const { loadCollaborationPeers } = await loadPeerLoaders({
117
+ [specifier]: { default: {} },
118
+ });
119
+
120
+ await expect(loadCollaborationPeers()).rejects.toThrow(
121
+ /@hocuspocus\/provider and yjs/,
122
+ );
123
+ });
124
+
125
+ it("marks a missing peer permanent and leaves any other failure retryable", async () => {
126
+ // editor-lazy.ts reads this distinction to decide whether a remount may
127
+ // try the import again.
128
+ const { loadDocumentEditorPeers } = await loadPeerLoaders({
129
+ "@tiptap/starter-kit": { default: {} },
130
+ });
131
+
132
+ await expect(loadDocumentEditorPeers()).rejects.toSatisfy(isMissingEditorPeersError);
133
+ expect(isMissingEditorPeersError(new Error("Failed to fetch dynamically imported module"))).toBe(
134
+ false,
135
+ );
136
+ });
137
+
138
+ it("reports an unresolved import as a permanent missing peer and keeps the cause", async () => {
139
+ // The rejection a throwing stub gives must become the install list, so a
140
+ // consumer reads which packages to add, and must count as permanent so a
141
+ // remount does not retry an import that cannot start to succeed.
142
+ const resolutionFailure = new Error('Could not resolve "@tiptap/starter-kit"');
143
+ const mapped = asMissingEditorPeersError(resolutionFailure, "install the peers");
144
+
145
+ expect(isMissingEditorPeersError(mapped)).toBe(true);
146
+ expect(mapped).toHaveProperty("cause", resolutionFailure);
147
+ // The install list holds every peer the surface needs, so the message also
148
+ // names the one that is actually absent.
149
+ expect((mapped as Error).message).toBe(
150
+ "install the peers @tiptap/starter-kit did not resolve.",
151
+ );
152
+ });
153
+
154
+ it("names the caret package rather than the collaboration package it contains", async () => {
155
+ // "@tiptap/extension-collaboration" is a prefix of the caret specifier, so
156
+ // a naive substring match reports the wrong package.
157
+ const caretFailure = new Error(
158
+ 'Could not resolve "@tiptap/extension-collaboration-caret"',
159
+ );
160
+ const mapped = asMissingEditorPeersError(caretFailure, "install the peers");
161
+
162
+ expect((mapped as Error).message).toBe(
163
+ "install the peers @tiptap/extension-collaboration-caret did not resolve.",
164
+ );
165
+ });
166
+
167
+ it("leaves a resolution failure that names no peer alone, so it stays retryable", async () => {
168
+ // An application chunk, or a dependency of a peer that did load, can fail
169
+ // to resolve too. Installing the editor peers would not fix that, and
170
+ // marking it permanent would stop a remount from trying again.
171
+ const unrelated = new Error("Cannot find module './app-chunk-a91f.js'");
172
+ const mapped = asMissingEditorPeersError(unrelated, "install the peers");
173
+
174
+ expect(mapped).toBe(unrelated);
175
+ expect(isMissingEditorPeersError(mapped)).toBe(false);
176
+ });
177
+
178
+ it("treats a @tiptap/core failure as a missing peer, though no loader imports it", async () => {
179
+ // The tiptap packages need @tiptap/core in turn, so a consumer that
180
+ // resolves it to nothing breaks exactly as one missing @tiptap/react
181
+ // does. Leaving it out of the list left that failure retryable.
182
+ const coreFailure = new Error('Could not resolve "@tiptap/core"');
183
+ const mapped = asMissingEditorPeersError(coreFailure, "install the peers");
184
+
185
+ expect(isMissingEditorPeersError(mapped)).toBe(true);
186
+ expect((mapped as Error).message).toBe(
187
+ "install the peers @tiptap/core did not resolve.",
188
+ );
189
+ });
190
+
191
+ it("keeps the install list alone when the failure names several peers", async () => {
192
+ const both = new Error(
193
+ 'Could not resolve "@tiptap/react" or "@hocuspocus/provider"',
194
+ );
195
+ const mapped = asMissingEditorPeersError(both, "install the peers");
196
+
197
+ expect(isMissingEditorPeersError(mapped)).toBe(true);
198
+ expect((mapped as Error).message).toBe("install the peers");
199
+ });
200
+
201
+ it("leaves a transient chunk failure unchanged, so a remount can retry it", async () => {
202
+ const transient = new Error("Failed to fetch dynamically imported module");
203
+
204
+ expect(asMissingEditorPeersError(transient, "install the peers")).toBe(transient);
205
+ expect(isMissingEditorPeersError(transient)).toBe(false);
206
+ });
207
+
208
+ it("names the install list when a peer carries the wrong member type", async () => {
209
+ const { loadDocumentEditorPeers } = await loadPeerLoaders({
210
+ "@tiptap/react": { useEditor: undefined, EditorContent: undefined },
211
+ });
212
+
213
+ await expect(loadDocumentEditorPeers()).rejects.toThrow(
214
+ /Install @tiptap\/react and @tiptap\/starter-kit/,
215
+ );
216
+ });
217
+
218
+ it("accepts the shapes the installed peers really have", async () => {
219
+ // The other cases in this file describe the peers, so nothing here would
220
+ // notice a tiptap release that moves `configure` off the default export.
221
+ // Loading the real packages is what turns that into a failure here rather
222
+ // than in a consumer's editor.
223
+ vi.resetModules();
224
+ for (const specifier of Object.keys(installedPeers)) {
225
+ vi.doUnmock(specifier);
226
+ }
227
+ const { loadCollaborationPeers } = await import("./editor-peers");
228
+
229
+ const peers = await loadCollaborationPeers();
230
+ // Prove the substitutions are gone; against the stubs this case would
231
+ // pass without reading a real package at all.
232
+ expect(peers.starterKit.default).not.toBe(installedPeers["@tiptap/starter-kit"].default);
233
+ expect(typeof peers.starterKit.default.configure).toBe("function");
234
+ expect(typeof peers.collaboration.default.configure).toBe("function");
235
+ expect(typeof peers.collaborationCaret.default.configure).toBe("function");
236
+ });
237
+
238
+ it("keeps the local editor usable when only a collaboration peer is missing", async () => {
239
+ // sandbox-ui installs the tiptap packages alone, so the local markdown
240
+ // editor must not start to require yjs or Hocuspocus.
241
+ const { loadCollaborationPeers, loadDocumentEditorPeers } = await loadPeerLoaders({
242
+ yjs: { Doc: undefined },
243
+ });
244
+
245
+ await expect(loadDocumentEditorPeers()).resolves.toBeDefined();
246
+ await expect(loadCollaborationPeers()).rejects.toThrow(
247
+ /@hocuspocus\/provider and yjs/,
248
+ );
249
+ });
250
+ });