From 987f1e0bbb1b92f0f9ac3f81fd267ac95b5c1c0e Mon Sep 17 00:00:00 2001 From: "Shaun A. Noordin" Date: Sat, 2 Sep 2023 03:25:13 +0800 Subject: [PATCH] DataManager: add notes on useMemo workarounds --- app/pages/lab-pages-editor/DataManager.jsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/pages/lab-pages-editor/DataManager.jsx b/app/pages/lab-pages-editor/DataManager.jsx index 571c91636a..f7cec5380a 100644 --- a/app/pages/lab-pages-editor/DataManager.jsx +++ b/app/pages/lab-pages-editor/DataManager.jsx @@ -24,6 +24,8 @@ function DataManager({ status: 'ready' }); + const [randomFlagToPromptMemoUpdate, setRandomFlagToPromptMemoUpdate] = useState(0); + // Fetch workflow when the component loads for the first time. // See notes about 'key' prop, to ensure states are reset: // https://react.dev/learn/you-might-not-need-an-effect#resetting-all-state-when-a-prop-changes @@ -82,13 +84,23 @@ function DataManager({ workflow: apiData.workflow, status: 'ready' }); + + // Hmmm... this seems to be the only thing that's updating the context properly. + // Without it, it seems that setApiData() isn't changing the value + // (object reference) of`apiData.workflow`, which means the useMemo + // doesn't realise that oohhh wait I think I get it now. + // TODO: how to indicate that the value of the apiData.workflow object + // has changed when the change is local to the resource itself? + // Does the workflow object have an internal version tracker? + // @shaunanoordin 20230902 + setRandomFlagToPromptMemoUpdate(Math.floor(Math.random() * 10000)); } return { workflow: apiData.workflow, update }; - }, [apiData.workflow]); // Note to self: change this to workflowId? + }, [apiData.workflow, randomFlagToPromptMemoUpdate]); if (!workflowId) return (
ERROR: no Workflow ID specified
); // if (!workflow) return null