Avoid repeated canvas scans during drag registration
This commit is contained in:
1 parent
d41eda7050
commit
c023a98052
3 files changed
+49
-20
No files matched your search
@@ -74,6 +74,38 @@ function fixture(onMove: MountEditorOptions["onMove"] = () => false) {
|
||||
};
|
||||
}
|
||||
|
||||
test("large canvas registration scans blocks once and preserves interleaved slot order", () => {
|
||||
const f = fixture();
|
||||
f.root.replaceChildren();
|
||||
for (let i = 0; i < 300; i++) {
|
||||
const node = f.document.createElement("div");
|
||||
node.dataset.blockId = String(i);
|
||||
node.dataset.blockParent = `parent:${i % 3}`;
|
||||
node.dataset.blockSlot = "content";
|
||||
f.root.append(node);
|
||||
}
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const slot = f.document.createElement("div");
|
||||
slot.dataset.blockParent = `parent:${i}`;
|
||||
slot.dataset.blockSlotTarget = "content";
|
||||
f.root.append(slot);
|
||||
}
|
||||
const query = f.root.querySelectorAll.bind(f.root);
|
||||
let scans = 0;
|
||||
f.root.querySelectorAll = ((selector: string) => {
|
||||
if (selector === "[data-block-id][data-block-parent][data-block-slot]") scans++;
|
||||
return query(selector);
|
||||
}) as typeof f.root.querySelectorAll;
|
||||
f.editor.refresh();
|
||||
const backend = f.backends.at(-1)!;
|
||||
expect(scans).toBe(1);
|
||||
expect(backend.registrations.map(({ id, group, index }) => ({ id, group, index }))).toEqual(
|
||||
Array.from({ length: 300 }, (_, i) => ({ id: String(i), group: JSON.stringify([`parent:${i % 3}`, "content"]), index: Math.floor(i / 3) })),
|
||||
);
|
||||
expect(backend.zones.map(zone => zone.group)).toEqual([JSON.stringify(["parent:3", "content"])]);
|
||||
f.editor.destroy();
|
||||
});
|
||||
|
||||
test("cancelled optimistic moves restore original DOM nodes across containers", async () => {
|
||||
const f = fixture();
|
||||
const a = f.root.querySelector('[data-block-id="a"]')!;
|
||||
|
||||
Reference in new issue
Block a user