@homebound/form-state 2.22.3 → 2.22.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,7 +31,9 @@ function newListFieldState(parentCopy, parentInstance, parentState, key, rules,
31
31
  if (!childState) {
32
32
  for (const [, otherState] of rowMap.entries()) {
33
33
  if (otherState.isSameEntity(child)) {
34
- otherState.set(child, opts);
34
+ // If we're being called from `list.rows`, we should be careful to not trigger mutations
35
+ if (!(opts === null || opts === void 0 ? void 0 : opts.skipSet))
36
+ otherState.set(child, opts);
35
37
  rowMap.set(child, otherState);
36
38
  return otherState;
37
39
  }
@@ -100,7 +102,7 @@ function newListFieldState(parentCopy, parentInstance, parentState, key, rules,
100
102
  (0, utils_1.fail)();
101
103
  // Avoid using `this.value` to avoid registering `_childTick` as a dependency
102
104
  const value = parentInstance[key];
103
- return (value || []).map((child) => getOrCreateChildState(child));
105
+ return (value || []).map((child) => getOrCreateChildState(child, { skipSet: true }));
104
106
  },
105
107
  // TODO Should this be true when all rows are touched?
106
108
  get touched() {
@@ -442,6 +442,20 @@ describe("formState", () => {
442
442
  a1.books.remove(0);
443
443
  expect(a1.dirty).toBeFalsy();
444
444
  });
445
+ it("handles list fields with duplicate ids", () => {
446
+ // Given an author that incorrectly has duplicate books
447
+ const a1 = createAuthorInputState({
448
+ books: [
449
+ { id: "b:1", title: "b1" },
450
+ { id: "b:1", title: "b2" },
451
+ ],
452
+ });
453
+ // Then it didn't blow up
454
+ expect(a1.books.dirty).toBeFalsy();
455
+ // And the 1st book won
456
+ expect(a1.books.rows[0].title.value).toBe("b1");
457
+ expect(a1.books.rows[1].title.value).toBe("b1");
458
+ });
445
459
  it("calls maybeAutoSave when adding or removing to a list", () => {
446
460
  const maybeAutoSave = jest.fn();
447
461
  const a1 = createAuthorInputState({ books: [] }, maybeAutoSave);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/form-state",
3
- "version": "2.22.3",
3
+ "version": "2.22.4",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",