github statelyai/xstate @xstate/store@3.10.0

2 days ago

Minor Changes

  • #5323 cb08332 Thanks @davidkpiano! - Added support for effect-only transitions that don't trigger state updates. Now, when a transition returns the same state but includes effects, subscribers won't be notified of a state change, but the effects will still be executed. This helps prevent unnecessary re-renders while maintaining side effect functionality.

    it('should not trigger update if the snapshot is the same even if there are effects', () => {
      const store = createStore({
        context: { count: 0 },
        on: {
          doNothing: (ctx, _, enq) => {
            enq.effect(() => {
              // …
            });
            return ctx; // Context is the same, so no update is triggered
            // This is the same as not returning anything (void)
          }
        }
      });
    
      const spy = vi.fn();
      store.subscribe(spy);
    
      store.trigger.doNothing();
      store.trigger.doNothing();
    
      expect(spy).toHaveBeenCalledTimes(0);
    });

Don't miss a new xstate release

NewReleases is sending notifications on new releases.