Skip to content

Conversation

davidkpiano
Copy link
Member

  • Removed unused setter function and associated recipe parameter.
  • Updated transition logic to prevent unnecessary updates when the snapshot remains unchanged.
  • Enhanced tests to verify behavior of effect-only and emit-only transitions, ensuring no updates trigger when the snapshot is the same.

- Removed unused setter function and associated recipe parameter.
- Updated transition logic to prevent unnecessary updates when the snapshot remains unchanged.
- Enhanced tests to verify behavior of effect-only and emit-only transitions, ensuring no updates trigger when the snapshot is the same.
@davidkpiano davidkpiano requested a review from Andarist July 6, 2025 23:33
Copy link

changeset-bot bot commented Jul 6, 2025

🦋 Changeset detected

Latest commit: 5eda50b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@xstate/store Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

store.getSnapshot().context.count satisfies string;
});

it('should not trigger update if the snapshot is the same', () => {
Copy link
Collaborator

@Andarist Andarist Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note this diverges from XState too:

import { createActor, createMachine } from "xstate";

const m = createMachine({
  on: {
    FOO: {
      actions: () => {},
    },
  },
});

const a = createActor(m).start();

let s = a.getSnapshot();

a.subscribe((_s) => {
  console.log("next", s === _s, _s);
  s = _s;
});

a.send({ type: "FOO" });
a.send({ type: "FOO" });
a.send({ type: "FOO" });

With the above we get:
Screenshot 2025-07-07 at 08 56 07

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about this behavior? If only actions/effects occur (invisible to the state, at least right now), then the state is going to be exactly the same. But I guess that's the responsibility of the consumer to "filter"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here, I think it would be totally OK to filter those out - but I think it would be great if this could be consistent between XState libraries.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think in XState v6, the purpose of the observer is to observe snapshot changes, so notifying on the same snapshot isn't useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants