Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Reenter in one state node also triggers parallel (sibling) node to reenter #5162

Open
CodingDive opened this issue Dec 31, 2024 · 0 comments
Labels

Comments

@CodingDive
Copy link
Contributor

CodingDive commented Dec 31, 2024

XState version

XState version 5

Description

Hey! Thank you for all your continued work! ❤️🫡

I have a state machine with some parallel states. When defining reenter: true in a state transion of one of them, all the siblings also reenter.

import { createMachine, assign, fromPromise, setup } from "xstate";

export const machine = createMachine({
  id: "reentrytest",
  type: "parallel",
  context: {
    numberOfTimesParallelNodeIsEntered: 0,
  },
  states: {
    someStateWithReentry: {
      entry: () => void console.log("I expect this to be called twice"),
      initial: "a",
      states: {
        a: {},
        b: {},
      },
      on: {
        REENTER_A: {
          target: ".a",
          reenter: true,
        },
      },
    },
    parallelStateWithNoReentry: {
      entry: [
        assign({
          numberOfTimesParallelNodeIsEntered: ({ context }) =>
            context.numberOfTimesParallelNodeIsEntered + 1,
        }),
        ({ context }) =>
          context.numberOfTimesParallelNodeIsEntered > 1 &&
          console.log(
            "Oops, I definitely don't expect this entry action to be called a second time!"
          ),
      ],
      initial: "c",
      states: {
        c: {
          on: {
            GO_TO_D: {
              target: "d",
            },
          },
        },
        d: {},
      },
    },
  },
});

Expected result

Only the node whose state transition has defined reenter: true should reenter if I understand the docs correctly https://stately.ai/docs/transitions#re-entering

Actual result

All parallel sibling state nodes also reenter

Reproduction

https://codesandbox.io/p/sandbox/vigorous-grass-7xrhqc?file=%2Fsrc%2Fmachine.ts%3A32%2C23&workspaceId=ws_6NRGN9nh2CKAFqdS5fatLX

Additional context

Latest @xstate/react and xstate

@CodingDive CodingDive added the bug label Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant