From d6dab34d0678e14aa7f2bfca4191c1a70937f4d9 Mon Sep 17 00:00:00 2001 From: Thomas Zemp Date: Fri, 20 Dec 2024 13:01:57 +0100 Subject: [PATCH] fix: prevent stale cached values from loading as initial vals --- src/data-workspace/data-workspace.js | 6 +++++- src/data-workspace/form-wrapper.js | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/data-workspace/data-workspace.js b/src/data-workspace/data-workspace.js index a34f7ebaf..2e4d12585 100644 --- a/src/data-workspace/data-workspace.js +++ b/src/data-workspace/data-workspace.js @@ -81,7 +81,11 @@ export const DataWorkspace = ({ selectionHasNoFormMessage }) => { // We want to block initialization of form if in-flight // or else we might use stale data that won't be updated once request completes - if (initialDataValuesFetch.isFetching) { + if ( + initialDataValuesFetch.isFetching || + (!initialDataValuesFetch.isFetchedAfterMount && + !initialDataValuesFetch.isPaused) + ) { return ( diff --git a/src/data-workspace/form-wrapper.js b/src/data-workspace/form-wrapper.js index d44445304..eb968d719 100644 --- a/src/data-workspace/form-wrapper.js +++ b/src/data-workspace/form-wrapper.js @@ -1,5 +1,5 @@ import PropTypes from 'prop-types' -import React, { useLayoutEffect, useState } from 'react' +import React, { useEffect, useState } from 'react' import { useValueStore } from '../shared/index.js' function mapObject(input, callback) { @@ -35,7 +35,7 @@ export function FormWrapper({ children, dataValueSet, validFormKey }) { useValueStore((state) => state.getInitialDataValues())?.formKey === validFormKey - useLayoutEffect(() => { + useEffect(() => { if (setInitialDataValues && initialValues && validFormKey) { setInitialDataValues(initialValues, validFormKey) }