Restore React purity checks and streamline inline drafts
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
This commit is contained in:
parent
2bff58f08c
commit
b9cc77a4d1
8 changed files with 111 additions and 10 deletions
34
e2e/fixtures/inline-edit-probe.js
Normal file
34
e2e/fixtures/inline-edit-probe.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// Rôle : monte le hook d'édition réel sous StrictMode pour observer ses commits DOM.
|
||||
import { createElement, StrictMode, useLayoutEffect } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { flushSync } from "react-dom";
|
||||
import { useInlineEdit } from "../../website/src/hooks/useInlineEdit.js";
|
||||
|
||||
export function mountInlineEditProbe(element, contentEditable) {
|
||||
const commits = [];
|
||||
const renders = [];
|
||||
const root = createRoot(element);
|
||||
|
||||
function Probe({ value }) {
|
||||
const edit = useInlineEdit({
|
||||
value,
|
||||
onCommit: (next) => commits.push(next),
|
||||
blurOnEscape: true
|
||||
});
|
||||
useLayoutEffect(() => {
|
||||
renders.push({ value, draft: edit.draft });
|
||||
});
|
||||
return createElement("section", null,
|
||||
contentEditable
|
||||
? createElement("div", edit.getContentEditableProps({ role: "textbox", "aria-label": "Edit" }))
|
||||
: createElement("input", edit.getInputProps({ type: "text", "aria-label": "Edit" })),
|
||||
createElement("button", { type: "button" }, "Outside")
|
||||
);
|
||||
}
|
||||
|
||||
function update(value) {
|
||||
flushSync(() => root.render(createElement(StrictMode, null, createElement(Probe, { value }))));
|
||||
}
|
||||
update("Initial");
|
||||
return { update, commits, renders, unmount: () => root.unmount() };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue