Skip to content

fix: preserve action identity across store re-exports - #3221

Closed
boyfeiyu wants to merge 1 commit into
vuejs:v4from
boyfeiyu:boyf-1053-cross-store-action-identity
Closed

boyfeiyu wants to merge 1 commit into
vuejs:v4from
boyfeiyu:boyf-1053-cross-store-action-identity

Conversation

@boyfeiyu

@boyfeiyu boyfeiyu commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Returning another store's action from a setup store currently reuses its wrapper. For example, return { advance: original.increment } renames subsequent original.increment() notifications to advance, while facade.advance() never notifies the facade's subscribers.

Give each store's public action its own subscription identity while delegating to the source action with its original store context. Same-store helper aliases retain their own names without duplicate notifications. Add regression coverage for aliases, chained facades, identical store IDs across Pinia instances, helper reuse, arguments, return values, errors and Promise callback ordering, and document the behavior.

Validated independently against the complete commit:

  • Reproduced both failures on the unchanged base; both controls passed.
  • Stock Pinia Vitest project: 29 files, 248 tests passed; 3 existing skips and 2 existing todos.
  • Root TypeScript build, all five Pinia build formats, declaration tests and production dist import passed.

Whole-workspace tests, lint and other package builds were not run.

Summary by CodeRabbit

  • Bug Fixes
    • Re-exported actions now preserve the original action’s store context and name when called. Subscribers on both the source and receiving stores are notified with the appropriate store and action details.
  • Documentation
    • Clarified how action notifications work when a setup store returns an action from another store.

@netlify

netlify Bot commented Nov 21, 2026

Copy link
Copy Markdown

👷 Deploy request for pinia-playground pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit bd93064

@netlify

netlify Bot commented Nov 21, 2026

Copy link
Copy Markdown

👷 Deploy request for pinia-official pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit bd93064

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The action wrapper now tracks the source store and original function for re-exported actions. Calls use the source store context, and subscribers on both stores receive notifications with their respective store and action names.

Changes: Re-exported actions

Layer / File(s) Summary
Track action ownership and aliases
packages/pinia/src/store.ts
The action marker records the owning store and original function. The wrapper reuses compatible wrappers and unwraps the original function when creating a differently named alias.
Dispatch calls and validate notifications
packages/pinia/src/store.ts, packages/pinia/__tests__/reexportActions.spec.ts, packages/docs/core-concepts/actions.md
Re-exported calls use the source store as their context. Both stores receive action notifications with their own store and action names. Tests cover aliases, callback behavior, return values, and errors; documentation describes the notifications.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant FacadeStore
  participant ActionWrapper
  participant FacadeSubscriber
  participant SourceSubscriber
  participant SourceStore
  FacadeStore->>ActionWrapper: Call re-exported action
  ActionWrapper->>FacadeSubscriber: Notify with facade store and action name
  ActionWrapper->>SourceSubscriber: Notify with source store and action name
  ActionWrapper->>SourceStore: Invoke original action with source store context
Loading

Suggested reviewers: posva

Merge Risk: Minimal · up to bd930

This fixes setup stores that return another store's action, so subscribers on both stores now receive notifications with their own store and action names. The change is confined to the action wrapper, has dedicated regression tests and documentation, and no concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: preserve action identity across store re-exports" matches the main change in the changeset. The store.ts changes keep same-store wrappers, unwrap the original function for differently …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix: preserve action identity across store re-exports" matches the main change in the changeset. The store.ts changes keep same-store wrappers, unwrap the original function for differently named aliases, and invoke re-exported actions with their source store as this. The new reexportActions.spec.ts covers re-export identity and delegation, and the docs describe the notification behavior. The title is specific and concise, and it is consistent with the PR objectives.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ce7661af-68f2-46cf-833d-a9a96ddf0aae
Commits

Reviewing files that changed from the base of the PR and between 4023d12 and bd93064.

Files selected for processing: 3

  • packages/docs/core-concepts/actions.md
  • packages/pinia/__tests__/reexportActions.spec.ts
  • packages/pinia/src/store.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@pinia/nuxt@3221
npm i https://pkg.pr.new/pinia@3221
npm i https://pkg.pr.new/@pinia/testing@3221

commit: bd93064

@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.40%. Comparing base (05ece25) to head (bd93064).
⚠️ Report is 2 commits behind head on v4.

Files with missing lines Patch % Lines
packages/pinia/src/store.ts 92.30% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##               v4    #3221      +/-   ##
==========================================
- Coverage   93.50%   93.40%   -0.11%     
==========================================
  Files          12       12              
  Lines         462      470       +8     
  Branches      138      144       +6     
==========================================
+ Hits          432      439       +7     
  Misses         13       13              
- Partials       17       18       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@posva

posva commented Nov 22, 2026

Copy link
Copy Markdown
Member

Thanks but you shouldn’t be doing that, so this is fine like it is

@posva posva closed this Nov 22, 2026
@github-project-automation github-project-automation Bot moved this from 🆕 Triaging to ✅ Done in Pinia Roadmap Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants