Skip to content

Commit cee024f

Browse files
fix(overmind-statechart): avoid throwing config error when fast refresh kicks in
React's fast refresh reruns `statechart` when a module that contains this call is edited. As the statechart was already initialized, a config error was thrown since `states` and `matches` were already present in the current state. To avoid throwing this error, it is now only thrown when the statechart is first initialized.
1 parent 574e486 commit cee024f

File tree

1 file changed

+2
-2
lines changed
  • packages/node_modules/overmind-statechart/src

1 file changed

+2
-2
lines changed

packages/node_modules/overmind-statechart/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,13 @@ export function statechart<
272272
const actions = config.actions || {}
273273
const state = config.state || {}
274274

275-
if (config.state && (config.state as any).states) {
275+
if (currentInstance !== undefined && config.state && (config.state as any).states) {
276276
throw new Error(
277277
`Overmind statecharts: You have already defined the state "states" in your configuration. Statecharts needs this, please rename it`
278278
)
279279
}
280280

281-
if (config.state && (config.state as any).matches) {
281+
if (currentInstance !== undefined && config.state && (config.state as any).matches) {
282282
throw new Error(
283283
`Overmind statecharts: You have already defined the state "matches" in your configuration. Statecharts needs this, please rename it`
284284
)

0 commit comments

Comments
 (0)