fix(forms): use Object.hasOwn for stale-field diff in signal forms - #70233
Open
arshsmith1 wants to merge 2 commits into
Open
fix(forms): use Object.hasOwn for stale-field diff in signal forms#70233arshsmith1 wants to merge 2 commits into
arshsmith1 wants to merge 2 commits into
Conversation
maybeRemoveStaleObjectFields checks whether a previously materialized child key still exists on the object model with value.hasOwnProperty(key). When the model mirrors untrusted JSON that carries an own field named hasOwnProperty, that data value shadows the method and the call throws a TypeError, crashing the structural diff during the reactive children computation. The sibling maybeRemoveStaleArrayFields already uses Object.hasOwn, so switch the object path to Object.hasOwn(value, key) to match. Valid models diff identically.
JeanMeche
reviewed
Aug 17, 2026
| }); | ||
| }); | ||
|
|
||
| describe('object models with shadowing keys', () => { |
Member
There was a problem hiding this comment.
Do you mind dropping that unecessary describe ?
Contributor
Author
There was a problem hiding this comment.
Done, dropped the nested describe and moved the test up into the parent block.
JeanMeche
reviewed
Aug 17, 2026
Comment on lines
+138
to
+139
| const data = signal<Record<string, unknown>>({a: '', hasOwnProperty: ''}); | ||
| const f = form(data, {injector: TestBed.inject(Injector)}) as any; |
Member
There was a problem hiding this comment.
We can probably improve the typings and drop that any.
Contributor
Author
There was a problem hiding this comment.
Good call. Letting the signal infer the model type gives a real FieldTree, so the any is gone and f.a().value() types through cleanly.
Drop the extra describe block and rely on inferred typings instead of an any cast in the stale-field diff regression test. Signed-off-by: arshiya tabasum <arshi@bugqore.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
PR Type
What is the current behavior?
Issue Number: N/A
maybeRemoveStaleObjectFieldsinpackages/forms/signals/src/field/structure.tsdiffs the previously materialized child keys against the current object model withvalue.hasOwnProperty(key). When a form model mirrors untrusted JSON that carries an own field literally namedhasOwnProperty, that data value shadows the method, so the call throwsTypeError: value.hasOwnProperty is not a functionand the structural diff crashes inside the reactive children computation. The siblingmaybeRemoveStaleArrayFieldsin the same file already avoids this by usingObject.hasOwn, so only the object path is affected.What is the new behavior?
The object path now uses
Object.hasOwn(value, key), matching the array sibling. Models without ahasOwnPropertyfield diff exactly as before; a model that happens to carry that key no longer crashes the diff. Added a regression test instructure.spec.tsthat materializes an object form, then updates it to a value carrying ahasOwnPropertykey and asserts the recompute does not throw.Does this PR introduce a breaking change?
Other information