Skip to content

Commit 91acf03

Browse files
Freeze editor pane during note switch to prevent content flash
When switching notes, React Query's placeholderData kept the previous note's data flowing, causing a brief flash of old content before the new editor mounted. Freeze editor pane props while isPlaceholderData is true so the current editor stays in place until the new note loads.
1 parent e600920 commit 91acf03

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/features/shell/use-shell-controller.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ export function useShellController() {
926926
const latestRef = useRef(currentHandlers);
927927
latestRef.current = currentHandlers;
928928

929-
const editorPaneProps = useMemo(
929+
const nextEditorPaneProps = useMemo(
930930
() => ({
931931
archivedAt: currentNote?.archivedAt ?? null,
932932
deletedAt: currentNote?.deletedAt ?? null,
@@ -1019,6 +1019,16 @@ export function useShellController() {
10191019
],
10201020
);
10211021

1022+
// Freeze editor pane props while React Query is showing placeholder data
1023+
// from the previous note, so the old note's content doesn't flash.
1024+
const editorPanePropsRef = useRef(nextEditorPaneProps);
1025+
if (!noteQuery.isPlaceholderData) {
1026+
editorPanePropsRef.current = nextEditorPaneProps;
1027+
}
1028+
const editorPaneProps = noteQuery.isPlaceholderData
1029+
? editorPanePropsRef.current
1030+
: nextEditorPaneProps;
1031+
10221032
const publishDialogProps = useMemo(
10231033
() => ({
10241034
initialTitle: currentNote?.title ?? "",

0 commit comments

Comments
 (0)