Skip to content

Commit aca767a

Browse files
committed
feat(super-editor): invalidate viewport geometry on sidebar-toggle (SD-3326)
ui.viewport.observe now fires when the comments rail opens or closes. The rail toggle shifts document geometry without a guaranteed layout repaint, so overlay consumers' cached rects would silently go stale. Bridges the existing sidebar-toggle signal into a geometry invalidation, reusing the 'layout' reason (consumers only re-query, so no new public reason is added).
1 parent 18a0d19 commit aca767a

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

packages/super-editor/src/ui/create-super-doc-ui.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,12 @@ export function createSuperDocUI(options: SuperDocUIOptions): SuperDocUI {
10131013
};
10141014
const onWindowScrollGeometry = () => scheduleGeometry('scroll');
10151015
const onWindowResizeGeometry = () => scheduleGeometry('resize');
1016+
// The comments rail toggling shifts/reflows document geometry but does
1017+
// not reliably emit a layout repaint on its own, so cached rects would
1018+
// silently go stale. Bridge the explicit sidebar-toggle signal into a
1019+
// geometry invalidation. Reuses the 'layout' reason — consumers only
1020+
// re-query on it, so no new public reason is warranted.
1021+
const onGeometrySidebar = () => scheduleGeometry('layout');
10161022
let domGeometryAttached = false;
10171023
const attachDomGeometryListeners = () => {
10181024
if (domGeometryAttached || typeof window === 'undefined') return;
@@ -1046,9 +1052,11 @@ export function createSuperDocUI(options: SuperDocUIOptions): SuperDocUI {
10461052
// zoom drives geometry (post-paint, tagged via onGeometryLayout) — separate
10471053
// from the slice recompute that SUPERDOC_EVENTS triggers.
10481054
superdoc.on?.('zoomChange', onGeometryZoom);
1055+
superdoc.on?.('sidebar-toggle', onGeometrySidebar);
10491056
teardown.push(() => {
10501057
SUPERDOC_EVENTS.forEach((name) => superdoc.off?.(name, scheduleNotify));
10511058
superdoc.off?.('zoomChange', onGeometryZoom);
1059+
superdoc.off?.('sidebar-toggle', onGeometrySidebar);
10521060
});
10531061
}
10541062

packages/super-editor/src/ui/viewport.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,4 +734,19 @@ describe('ui.viewport.observe — repaint reason (SD-3311 regression)', () => {
734734
expect(events).toEqual([{ reason: 'layout' }]);
735735
ui.destroy();
736736
});
737+
738+
it('fires a geometry invalidation on sidebar-toggle (reason "layout")', async () => {
739+
// The comments rail toggling shifts geometry without a guaranteed
740+
// layout repaint; observe must still notify so cached rects re-query.
741+
const { superdoc, emitSuperdoc } = makeGeometryStub();
742+
const ui = createSuperDocUI({ superdoc });
743+
const events: Array<{ reason: string }> = [];
744+
ui.viewport.observe((e) => events.push(e));
745+
746+
emitSuperdoc('sidebar-toggle', true);
747+
await nextFrame();
748+
749+
expect(events).toEqual([{ reason: 'layout' }]);
750+
ui.destroy();
751+
});
737752
});

0 commit comments

Comments
 (0)