fix: Revision diff not shown when previous revision loads late (#13140)

The revision editor builds its extensions once, on mount, and is remounted
via its `key` when they change. Since revisions.list stopped returning
content in #12822 the previous revision's data is fetched after the first
render, so the Diff extension is created on a later render — by which point
the editor has already been built without it and the key, which only
tracked `compareTo`, does not change.

The result is a revision view with neither diff highlights nor a change
count, which appears intermittent because it works whenever the previous
revision's content already happens to be in the store.

Include the diff inputs in the editor key so the editor is rebuilt when the
comparison content arrives, when the compared-against revision changes, and
when changes are toggled on or off.

Closes #12964
This commit is contained in:
udit
2026-07-29 23:15:52 -04:00
committed by GitHub
parent 647352f6a0
commit 64b931aad8
@@ -93,6 +93,17 @@ function RevisionViewer(props: Props, ref: React.Ref<TEditor>) {
];
}, [revision.data, comparisonData, showChanges]);
// The editor builds its extensions once, on mount, so it has to be remounted
// whenever the diff configuration changes. Revisions are listed without their
// content, so the revision being compared against — and with it the Diff
// extension — usually only arrives on a later render; without this neither
// the highlights nor the change count would ever appear.
const editorKey = [
showChanges ? "changes" : "no-changes",
compareToRevisionId ?? revision.before?.id ?? "none",
comparisonData ? "loaded" : "pending",
].join("-");
return (
<Flex auto column>
<DocumentTitle
@@ -109,7 +120,7 @@ function RevisionViewer(props: Props, ref: React.Ref<TEditor>) {
$rtl={revision.rtl}
/>
<Editor
key={compareToRevisionId}
key={editorKey}
ref={ref}
defaultValue={revision.data}
extensions={extensions}