Skip to content

Commit

Permalink
fix: prevent stale cached values from loading as initial vals
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Dec 20, 2024
1 parent de622f2 commit d6dab34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/data-workspace/data-workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<CenteredContent>
<CircularLoader />
Expand Down
4 changes: 2 additions & 2 deletions src/data-workspace/form-wrapper.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit d6dab34

Please sign in to comment.