Skip to content

Commit

Permalink
Fix: childrenState must be defined before other reactive node state…
Browse files Browse the repository at this point in the history
… specifically, before calling `createComputedExpression` or anything else that may exercise the `SubscribableDependency` interface.

TODO(?): detect this condition and throw a more meaningful error?
  • Loading branch information
eyelidlessness committed Apr 3, 2024
1 parent 89580e3 commit 0429f95
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
4 changes: 3 additions & 1 deletion packages/xforms-engine/src/instance/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export class Group
super(parent, definition);

const childrenState = createChildrenState<Group, GeneralChildNode>(this);

this.childrenState = childrenState;

const state = createSharedNodeState(
this.scope,
{
Expand All @@ -58,7 +61,6 @@ export class Group
}
);

this.childrenState = childrenState;
this.state = state;
this.engineState = state.engineState;
this.currentState = materializeCurrentStateChildren(state.currentState, childrenState);
Expand Down
7 changes: 4 additions & 3 deletions packages/xforms-engine/src/instance/RepeatInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export class RepeatInstance
) {
super(parent, definition);

const childrenState = createChildrenState<RepeatInstance, GeneralChildNode>(this);

this.childrenState = childrenState;

options.precedingPrimaryInstanceNode.after(this.contextNode);

const { precedingInstance } = options;
Expand All @@ -66,8 +70,6 @@ export class RepeatInstance
const [currentIndex, setCurrentIndex] = createSignal(initialIndex);

this.currentIndex = currentIndex;

const childrenState = createChildrenState<RepeatInstance, GeneralChildNode>(this);
const state = createSharedNodeState(
this.scope,
{
Expand All @@ -84,7 +86,6 @@ export class RepeatInstance
}
);

this.childrenState = childrenState;
this.state = state;
this.engineState = state.engineState;
this.currentState = materializeCurrentStateChildren(state.currentState, childrenState);
Expand Down
6 changes: 4 additions & 2 deletions packages/xforms-engine/src/instance/Root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ export class Root
) {
super(engineConfig, null, definition);

const childrenState = createChildrenState<Root, GeneralChildNode>(this);

this.childrenState = childrenState;

const reference = definition.nodeset;

this.rootReference = reference;
Expand All @@ -158,7 +162,6 @@ export class Root
const evaluator = instanceDOM.primaryInstanceEvaluator;
const { translations } = evaluator;
const { defaultLanguage, languages } = getInitialLanguageState(translations);
const childrenState = createChildrenState<Root, GeneralChildNode>(this);
const state = createSharedNodeState(
this.scope,
{
Expand All @@ -178,7 +181,6 @@ export class Root
}
);

this.childrenState = childrenState;
this.state = state;
this.engineState = state.engineState;
this.currentState = materializeCurrentStateChildren(state.currentState, childrenState);
Expand Down
4 changes: 3 additions & 1 deletion packages/xforms-engine/src/instance/Subtree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export class Subtree
super(parent, definition);

const childrenState = createChildrenState<Subtree, GeneralChildNode>(this);

this.childrenState = childrenState;

const state = createSharedNodeState(
this.scope,
{
Expand All @@ -55,7 +58,6 @@ export class Subtree
}
);

this.childrenState = childrenState;
this.state = state;
this.engineState = state.engineState;
this.currentState = materializeCurrentStateChildren(state.currentState, childrenState);
Expand Down

0 comments on commit 0429f95

Please sign in to comment.