From 11fab8767b486b96aae21d7a1551be6ccb0a45cc Mon Sep 17 00:00:00 2001 From: novikovfred Date: Fri, 7 Jun 2024 15:07:57 +0200 Subject: [PATCH 1/4] fix: type error, cannot create property --- packages/conform-dom/formdata.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/conform-dom/formdata.ts b/packages/conform-dom/formdata.ts index 30aa5111..f3312c9e 100644 --- a/packages/conform-dom/formdata.ts +++ b/packages/conform-dom/formdata.ts @@ -127,8 +127,14 @@ export function setValue( ? [] : {} : valueFn(pointer[key]); - - pointer[key] = newValue; + if ( + Object.isExtensible(pointer) && + !!nextKey && + !(Object.isSealed(pointer) && !(nextKey in pointer)) && + !(Object.isFrozen(pointer) && !(nextKey in pointer)) + ) { + pointer[key] = newValue; + } pointer = pointer[key]; } } From a5d570efb7ca0b979be97d8d519062620accba84 Mon Sep 17 00:00:00 2001 From: novikovfred Date: Fri, 7 Jun 2024 15:15:31 +0200 Subject: [PATCH 2/4] Empty-Commit From 47437e4a088da9a7ae1b39712ad71492a2a80b89 Mon Sep 17 00:00:00 2001 From: novikovfred Date: Fri, 7 Jun 2024 15:21:00 +0200 Subject: [PATCH 3/4] fix: type error, cannot create property --- packages/conform-dom/formdata.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/conform-dom/formdata.ts b/packages/conform-dom/formdata.ts index f3312c9e..741b6819 100644 --- a/packages/conform-dom/formdata.ts +++ b/packages/conform-dom/formdata.ts @@ -129,9 +129,9 @@ export function setValue( : valueFn(pointer[key]); if ( Object.isExtensible(pointer) && - !!nextKey && - !(Object.isSealed(pointer) && !(nextKey in pointer)) && - !(Object.isFrozen(pointer) && !(nextKey in pointer)) + !!key && + !(Object.isSealed(pointer) && !(key in pointer)) && + !(Object.isFrozen(pointer) && !(key in pointer)) ) { pointer[key] = newValue; } From 85f85dd7d6eca7bec1ba04cdb94b6f1c2ffd9284 Mon Sep 17 00:00:00 2001 From: novikovfred Date: Fri, 7 Jun 2024 15:44:01 +0200 Subject: [PATCH 4/4] fix: type error, cannot create property --- packages/conform-dom/formdata.ts | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/conform-dom/formdata.ts b/packages/conform-dom/formdata.ts index 741b6819..9c132265 100644 --- a/packages/conform-dom/formdata.ts +++ b/packages/conform-dom/formdata.ts @@ -127,18 +127,38 @@ export function setValue( ? [] : {} : valueFn(pointer[key]); - if ( - Object.isExtensible(pointer) && - !!key && - !(Object.isSealed(pointer) && !(key in pointer)) && - !(Object.isFrozen(pointer) && !(key in pointer)) - ) { + + if (canAddProperty(pointer, key)) { pointer[key] = newValue; } pointer = pointer[key]; } } +function canAddProperty( + obj: Object | Array, + property: string | number, +): boolean { + const propertyStr = + typeof property === 'number' ? property.toString() : property; + if (Object.prototype.hasOwnProperty.call(obj, propertyStr)) { + const descriptor = Object.getOwnPropertyDescriptor(obj, propertyStr); + if (descriptor && !descriptor.writable) { + return false; + } + } + if (!Object.isExtensible(obj)) { + return false; + } + if (Object.isSealed(obj) && !(propertyStr in obj)) { + return false; + } + if (Object.isFrozen(obj) && !(propertyStr in obj)) { + return false; + } + return true; +} + /** * Retrive the value from a target object by following the paths */