This is an automated email from the ASF dual-hosted git repository.

tiagobento pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools.git


The following commit(s) were added to refs/heads/main by this push:
     new 1b142645984 NO-ISSUE: Fix stale content when switching editors for the 
same file on KIE Sandbox (#2104)
1b142645984 is described below

commit 1b14264598440ea8f155b8addf6e367c56941c02
Author: Tiago Bento <[email protected]>
AuthorDate: Wed Dec 27 13:47:24 2023 -0500

    NO-ISSUE: Fix stale content when switching editors for the same file on KIE 
Sandbox (#2104)
---
 packages/online-editor/src/editor/EditorPage.tsx | 34 ++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/packages/online-editor/src/editor/EditorPage.tsx 
b/packages/online-editor/src/editor/EditorPage.tsx
index 9c3c027a453..58bcc13e31a 100644
--- a/packages/online-editor/src/editor/EditorPage.tsx
+++ b/packages/online-editor/src/editor/EditorPage.tsx
@@ -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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to