Skip to content

perf(react): stabilize useFlow/useStepFlow action references#721

Merged
ENvironmentSet merged 1 commit into
mainfrom
fix/stable-useflow-actions
Jul 7, 2026
Merged

perf(react): stabilize useFlow/useStepFlow action references#721
ENvironmentSet merged 1 commit into
mainfrom
fix/stable-useflow-actions

Conversation

@ENvironmentSet

@ENvironmentSet ENvironmentSet commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

useFlow and useStepFlow rebuilt their action object on every render, so the returned functions (push/replace/pop, pushStep/replaceStep/popStep) got a new reference on each render. This memoizes them so their references stay stable across renders.

coreStore.actions is already a stable reference for the lifetime of the store (created once in makeCoreStore, provided via context and never reassigned). So wrapping makeActions/makeStepActions in useMemo keyed on the core actions is enough to keep the returned functions referentially stable — the same approach usePrepare already uses.

🤖 Generated with Claude Code

useFlow and useStepFlow rebuilt their action object on every render, so
push/replace/pop and pushStep/replaceStep/popStep had a new reference each
render. Since the underlying core actions are already a stable reference,
memoize the returned actions on them (the same approach usePrepare uses) so
they stay referentially stable across renders — keeping them safe to place
in useEffect/useCallback dependency arrays without triggering unnecessary
re-runs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2fb9620

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

This PR includes changesets to release 1 package
Name Type
@stackflow/react Patch

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

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cb65d429-d9ea-4d5c-ab60-48328a798a7a

📥 Commits

Reviewing files that changed from the base of the PR and between efa5a4e and 2fb9620.

📒 Files selected for processing (3)
  • .changeset/stable-useflow-actions.md
  • integrations/react/src/useFlow.ts
  • integrations/react/src/useStepFlow.ts

Disabled knowledge base sources:

  • Jira integration is disabled
  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Kept action functions from useFlow and useStepFlow stable across renders, reducing unnecessary reference changes.
    • Improved consistency when using flow actions such as push, replace, and pop in React components.
  • Chores

    • Updated release notes to reflect the behavior change in the React hooks.

Walkthrough

This PR memoizes the action objects returned by useFlow and useStepFlow using useMemo keyed on coreActions, preventing new function references on every render. A changeset documents the patch-level fix for @stackflow/react.

Changes

Action Memoization

Layer / File(s) Summary
Memoize useFlow actions
integrations/react/src/useFlow.ts
Imports useMemo and wraps the returned Actions object in useMemo, recalculating only when coreActions changes.
Memoize useStepFlow actions
integrations/react/src/useStepFlow.ts
Imports useMemo and wraps the makeStepActions call in useMemo, depending on coreActions.
Changeset documentation
.changeset/stable-useflow-actions.md
Documents the patch-level fix for @stackflow/react describing referential stability of returned action functions.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Component
  participant useFlow
  participant useStepFlow
  participant useMemo

  Component->>useFlow: render
  useFlow->>useMemo: memoize Actions(coreActions)
  useMemo-->>useFlow: stable Actions reference
  useFlow-->>Component: return Actions

  Component->>useStepFlow: render
  useStepFlow->>useMemo: memoize StepActions(coreActions)
  useMemo-->>useStepFlow: stable StepActions reference
  useStepFlow-->>Component: return StepActions
Loading

Related Issues: None specified.

Related PRs: None specified.

Suggested labels: patch, react

Suggested reviewers: None specified.

🐰 A hop, a skip, a memo made,
No more fresh functions each render's shade,
push and pop now hold their form,
Stable actions through the storm.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/stable-useflow-actions

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying stackflow-demo with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1c24c88
Status: ✅  Deploy successful!
Preview URL: https://8fed06b6.stackflow-demo.pages.dev
Branch Preview URL: https://fix-stable-useflow-actions.stackflow-demo.pages.dev

View logs

@ENvironmentSet ENvironmentSet marked this pull request as ready for review July 7, 2026 12:51
@ENvironmentSet ENvironmentSet merged commit 91c433c into main Jul 7, 2026
6 of 8 checks passed
@ENvironmentSet ENvironmentSet deleted the fix/stable-useflow-actions branch July 7, 2026 12:51
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.

1 participant