From f98dbe0d659d9d5f6f65ba73cd235cda44b611b4 Mon Sep 17 00:00:00 2001 From: Tim Stevens Date: Fri, 10 Feb 2023 16:05:09 -0600 Subject: [PATCH 1/2] Update sanitizeDataForNewSchema.ts --- packages/utils/src/schema/sanitizeDataForNewSchema.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/utils/src/schema/sanitizeDataForNewSchema.ts b/packages/utils/src/schema/sanitizeDataForNewSchema.ts index 5c9c292faf..66aea8ab6f 100644 --- a/packages/utils/src/schema/sanitizeDataForNewSchema.ts +++ b/packages/utils/src/schema/sanitizeDataForNewSchema.ts @@ -16,7 +16,7 @@ const NO_VALUE = Symbol("no Value"); /** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the new * schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the nature * of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the old schema - * that are non-existent in the new schema are set to `undefined`. The data sanitization process has the following flow: + * that are non-existent in the new schema are removed. The data sanitization process has the following flow: * * - If the new schema is an object that contains a `properties` object then: * - Create a `removeOldSchemaData` object, setting each key in the `oldSchema.properties` having `data` to undefined @@ -80,6 +80,11 @@ export default function sanitizeDataForNewSchema< if (has(oldSchema, PROPERTIES_KEY)) { const properties = get(oldSchema, PROPERTIES_KEY, {}); Object.keys(properties).forEach((key) => { + // if new schema does not have removeOldSchemaData[key] + if (!has(newSchema, [PROPERTIES_KEY, key])) { + delete removeOldSchemaData[key]; + delete data[key]; + } if (has(data, key)) { removeOldSchemaData[key] = undefined; } From dd9822ef59cf3247781e1188e9f06e5c34229af6 Mon Sep 17 00:00:00 2001 From: Tim Stevens Date: Wed, 15 Feb 2023 14:16:34 -0600 Subject: [PATCH 2/2] Update oneOf_test.js --- packages/core/test/oneOf_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/test/oneOf_test.js b/packages/core/test/oneOf_test.js index b79cd510eb..edf1d7a701 100644 --- a/packages/core/test/oneOf_test.js +++ b/packages/core/test/oneOf_test.js @@ -1243,7 +1243,7 @@ describe("oneOf", () => { sinon.assert.calledWithMatch(onChange.lastCall, { formData: { craftTypes: [ - { keywords: [undefined], title: undefined, daysOfYear: undefined }, + { keywords: [undefined], title: undefined }, ], }, });