Skip to content

Commit b83a7f7

Browse files
author
Ole Martin Handeland
committed
Found a case where a language change seems to unmount FormDataWrite entirely and clear all state. Saving is trigged on unmount, but that saving isn't always done when re-mounting again, so DataModelsProvider would end up getting outdated initial form data for the next render.
1 parent 5f9b7ce commit b83a7f7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/features/datamodel/DataModelsProvider.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,17 @@ function BlockUntilLoaded({ children }: PropsWithChildren) {
256256
useSelector((state) => state);
257257
const actualCurrentTask = useCurrentLayoutSetId();
258258
const isPDF = useIsPdf();
259+
const mutations = useQueryClient()
260+
.getMutationCache()
261+
.findAll({ mutationKey: ['saveFormData'] });
262+
263+
if (mutations.some((m) => m.state.status === 'pending')) {
264+
// FormDataWrite automatically saves unsaved changes on unmount. If something happens above us in the render tree
265+
// that causes FormDataWrite to be unmounted (forcing it to save) and re-mounts everything (including us), we
266+
// should wait for that previously started save to complete. Otherwise, we'd end up saving outdated initial data
267+
// and cause a 409 when patching later.
268+
return <Loader reason='save-form-data' />;
269+
}
259270

260271
if (error) {
261272
// Error trying to fetch data, if missing rights we display relevant page

0 commit comments

Comments
 (0)