Skip to content

Commit

Permalink
Preserve default context on start from named state
Browse files Browse the repository at this point in the history
When an initial state is not passed to `service.start()`, `machine.initialState` is used, which is filled in with a lot of details, particularly a copy of the default `machine.context`.

When an initial state is passed as a `State` object, it is loaded directly, and it is assume that this comes with the desired `.context` value filled in.

But when an initial state is passed as a named state, like `interpret(machine).start("COMMENT_FORM")`, the resulting state has `.context === undefined` because nothing ever sets it. `State.from()`, which handles loading a string state to a full state object, already had an option to attach a context, but it was not used in this case.
  • Loading branch information
kousu authored Jul 26, 2019
1 parent a3215b7 commit f900f0a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export class Interpreter<
? this.machine.initialState
: initialState instanceof State
? this.machine.resolveState(initialState)
: this.machine.resolveState(State.from(initialState));
: this.machine.resolveState(State.from(initialState, this.machine.context));
});

if (this.options.devTools) {
Expand Down

0 comments on commit f900f0a

Please sign in to comment.