Skip to content

Commit 9aadd7b

Browse files
committed
fix: narrow React mutation handling and clean up Appium sessions
1 parent 382a7f1 commit 9aadd7b

4 files changed

Lines changed: 135 additions & 5 deletions

File tree

‎.claude/skills/ios-simulator/SKILL.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ not automated regression coverage or proof of physical-device/iPad/IME behavior.
1717

1818
- macOS, full Xcode selected, an installed iOS runtime, and Node.js/pnpm.
1919
- Docker for browser tests. Use only `vp` / `pnpm`, not npm/yarn.
20+
- Optional for recording review: FFmpeg (`ffmpeg` and `ffprobe`, available via
21+
`brew install ffmpeg`) for the contact-sheet commands in the debugging reference.
2022
- A local Safari-accessible dev server from **this checkout**. Another worktree
2123
may own the usual port; verify the URL rather than assuming port 5173.
2224
- An approved external temporary directory for sessions, logs, captures and driver

‎.claude/skills/ios-simulator/scripts/device.mjs‎

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ mkdirSync(artifacts, { recursive: true });
1818
const sessionFile = resolve(artifacts, "session.json");
1919
const server = process.env.APPIUM_URL ?? "http://127.0.0.1:4723";
2020

21+
class AppiumError extends Error {
22+
constructor(message, code) {
23+
super(message);
24+
this.code = code;
25+
}
26+
}
27+
2128
function request(method, path, body) {
2229
const url = new URL(`${server.replace(/\/$/, "")}${path}`);
2330
const data = body === undefined ? undefined : JSON.stringify(body);
@@ -40,7 +47,12 @@ function request(method, path, body) {
4047
try {
4148
const result = JSON.parse(text);
4249
if (res.statusCode >= 400 || result.value?.error) {
43-
reject(new Error(`${method} ${path}: ${text}`));
50+
reject(
51+
new AppiumError(
52+
`${method} ${path}: ${text}`,
53+
result.value?.error,
54+
),
55+
);
4456
} else {
4557
resolveRequest(result.value);
4658
}
@@ -59,6 +71,19 @@ function request(method, path, body) {
5971
});
6072
}
6173

74+
async function deleteSession(sessionId) {
75+
try {
76+
return await request("DELETE", `/session/${sessionId}`);
77+
} catch (error) {
78+
// An expired session is already closed. Do not mistake transport/server
79+
// failures for expiry: keep its saved ID available for a later retry.
80+
if (error instanceof AppiumError && error.code === "invalid session id") {
81+
return null;
82+
}
83+
throw error;
84+
}
85+
}
86+
6287
function write(path, data) {
6388
mkdirSync(dirname(resolve(path)), { recursive: true });
6489
writeFileSync(path, data);
@@ -95,7 +120,20 @@ if (action === "create") {
95120
},
96121
},
97122
});
98-
write(sessionFile, JSON.stringify(session, null, 2));
123+
try {
124+
write(sessionFile, JSON.stringify(session, null, 2));
125+
} catch (error) {
126+
// Without a saved ID, a later `close` cannot find the new remote session.
127+
try {
128+
await deleteSession(session.sessionId);
129+
} catch (cleanupError) {
130+
throw new AggregateError(
131+
[error, cleanupError],
132+
`Could not save or close Appium session ${session.sessionId}`,
133+
);
134+
}
135+
throw error;
136+
}
99137
await request("POST", `/session/${session.sessionId}/timeouts`, {
100138
script: 30_000,
101139
});
@@ -196,7 +234,7 @@ if (action === "create") {
196234
);
197235
break;
198236
case "close":
199-
result = await call("DELETE", "");
237+
result = await deleteSession(sessionId);
200238
unlinkSync(sessionFile);
201239
break;
202240
default:

‎packages/react/src/schema/ReactBlockSpec.browser.test.tsx‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,88 @@ import { expect, it } from "vite-plus/test";
77
import { BlockNoteViewRaw } from "../editor/BlockNoteView.js";
88
import { createReactBlockSpec } from "./ReactBlockSpec.js";
99

10+
it("keeps inline block state when React adds or removes contentDOM siblings", async () => {
11+
let mounts = 0;
12+
const stateful = createReactBlockSpec(
13+
{ type: "stateful", propSchema: {}, content: "inline" },
14+
{
15+
render: function StatefulBlock({ contentRef }) {
16+
const [count, setCount] = useState(0);
17+
const [showDetails, setShowDetails] = useState(false);
18+
useEffect(() => {
19+
mounts++;
20+
}, []);
21+
return (
22+
<div>
23+
<button contentEditable={false} onClick={() => setCount(count + 1)}>
24+
Count: {count}
25+
</button>
26+
<button
27+
contentEditable={false}
28+
onClick={() => setShowDetails(!showDetails)}
29+
>
30+
Toggle details
31+
</button>
32+
<div ref={contentRef}>
33+
{showDetails && <aside contentEditable={false}>Details</aside>}
34+
</div>
35+
</div>
36+
);
37+
},
38+
},
39+
)();
40+
const editor = BlockNoteEditor.create({
41+
schema: BlockNoteSchema.create().extend({ blockSpecs: { stateful } }),
42+
initialContent: [{ type: "stateful", content: "Editable text" }],
43+
});
44+
const host = document.createElement("div");
45+
document.body.append(host);
46+
const root = createRoot(host);
47+
try {
48+
flushSync(() => {
49+
root.render(
50+
<BlockNoteViewRaw
51+
editor={editor}
52+
formattingToolbar={false}
53+
linkToolbar={false}
54+
sideMenu={false}
55+
slashMenu={false}
56+
/>,
57+
);
58+
});
59+
await expect.poll(() => host.querySelectorAll("button").length).toBe(2);
60+
const button = host.querySelector("button")!;
61+
const toggle = host.querySelectorAll("button")[1];
62+
const content = host.querySelector("[data-node-view-content-react]");
63+
flushSync(() => button.click());
64+
const initialMounts = mounts;
65+
const documentBefore = editor.document;
66+
for (const visible of [true, false]) {
67+
flushSync(() => toggle.click());
68+
// Deliver mutations and allow ProseMirror's deferred DOM read to run.
69+
await new Promise<void>((resolve) => setTimeout(resolve, 100));
70+
expect(host.querySelector("button")).toBe(button);
71+
expect(button.textContent).toBe("Count: 1");
72+
expect(host.querySelector("aside") !== null).toBe(visible);
73+
expect(host.querySelector("[data-node-view-content-react]")).toBe(
74+
content,
75+
);
76+
expect(mounts).toBe(initialMounts);
77+
expect(editor.document).toEqual(documentBefore);
78+
}
79+
content!.textContent = "Native edit";
80+
await expect
81+
.poll(() => editor.document[0])
82+
.toMatchObject({
83+
content: [{ type: "text", text: "Native edit" }],
84+
});
85+
} finally {
86+
root.unmount();
87+
editor._tiptapEditor.destroy();
88+
host.remove();
89+
}
90+
});
91+
1092
it.each([false, true])(
1193
"keeps custom block state across wrapper attribute changes, framed=%s",
1294
async (framed) => {

‎packages/react/src/schema/ReactBlockSpec.tsx‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,19 @@ export function createReactBlockSpec<
596596
![
597597
...mutation.addedNodes,
598598
...mutation.removedNodes,
599-
].includes(contentDOM)
599+
].includes(contentDOM) &&
600+
[...mutation.addedNodes, ...mutation.removedNodes].some(
601+
(node) =>
602+
node.nodeType === 1 &&
603+
(node as Element).hasAttribute(
604+
"data-node-view-content-react",
605+
),
606+
)
600607
) {
601608
// TipTap's contentDOM.contains check misses native mobile
602609
// Enter cloning contentDOM into a sibling. Observe that
603-
// boundary, but not React attaching/detaching contentDOM.
610+
// boundary only for cloned content containers, not React
611+
// chrome or attaching/detaching the real contentDOM.
604612
// Open upstream PR (currently insufficient for this
605613
// nested wrapper): https://github.com/ueberdosis/tiptap/pull/8355
606614
// Recheck this workaround when that behavior changes.

0 commit comments

Comments
 (0)