Skip to content

Commit

Permalink
NO-ISSUE: Fix stale content when switching editors for the same file …
Browse files Browse the repository at this point in the history
…on KIE Sandbox (apache#2104)
  • Loading branch information
tiagobento authored Dec 27, 2023
1 parent 8708bfc commit 1b14264
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/online-editor/src/editor/EditorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,40 @@ export function EditorPage(props: Props) {
return editorEnvelopeLocator;
}, [editorEnvelopeLocator, props.fileRelativePath, settings.editors.useLegacyDmnEditor]);

// `workspaceFilePromise` is ONLY updated when there's an external change on this file (e.g., on another tab), but
// when we jump between the legacy and the new DMN Editor, `settingsAwareEditorEnvelopeLocator` changes,
// and if we don't update `embeddedEditorFile`, the new <EmbeddedEditor> will be rendered using the `embeddedEditorFile`
// that originally was used for opening the file, and the new chosen DMN Editor will display stale content.
useCancelableEffect(
useCallback(
({ canceled }) => {
workspaceFilePromise.data?.workspaceFile.getFileContentsAsString().then((content) => {
if (canceled.get()) {
return;
}

setEmbeddedEditorFile((prev) =>
!prev
? undefined
: {
...prev,
getFileContents: async () => content,
}
);
});
},
//
// This is a very unusual case.
// `workspaceFilePromise.data` should've been here, but we can't really add it otherwise
// the <EmbeddedEditor> component will blink on any edit.
// `settingsAwareEditorEnvelopeLocator` is added because it is the only case where the
// <EmbeddedEditor> should update for the same workspaceFile.
//
// eslint-disable-next-line react-hooks/exhaustive-deps
[settingsAwareEditorEnvelopeLocator]
)
);

return (
<OnlineEditorPage onKeyDown={onKeyDown}>
<PromiseStateWrapper
Expand Down

0 comments on commit 1b14264

Please sign in to comment.