From 3a387e31b5a1bea7cf35b4f22ca16f1772079371 Mon Sep 17 00:00:00 2001 From: David Matejka Date: Mon, 1 Jul 2024 14:17:59 +0200 Subject: [PATCH] fix(binding): in connectEntityAtField require marker for input state only --- packages/binding/src/core/operations/EntityOperations.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/binding/src/core/operations/EntityOperations.ts b/packages/binding/src/core/operations/EntityOperations.ts index 96d5d2175..e065346b1 100644 --- a/packages/binding/src/core/operations/EntityOperations.ts +++ b/packages/binding/src/core/operations/EntityOperations.ts @@ -67,7 +67,7 @@ export class EntityOperations { } for (const state of StateIterator.eachSiblingRealm(outerState)) { - const targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'connect') + const targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'connect', state === outerState) for (const targetHasOneMarker of targetHasOneMarkers) { const previouslyConnectedState = state.children.get(targetHasOneMarker.placeholderName) @@ -165,7 +165,7 @@ export class EntityOperations { const persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue) for (const state of StateIterator.eachSiblingRealm(outerState)) { - const targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'disconnect') + const targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'disconnect', state === outerState) for (const targetHasOneMarker of targetHasOneMarkers) { const stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName) @@ -286,10 +286,14 @@ export class EntityOperations { container: EntityFieldMarkersContainer, field: FieldName, type: 'connect' | 'disconnect', + mustExists: boolean, ): IterableIterator { const placeholders = container.placeholders.get(field) if (placeholders === undefined) { + if (!mustExists) { + return + } throw new BindingError(`Cannot ${type} at field '${field}' as it wasn't registered during static render.`) } const normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders]