Skip to content

fix(react-paypal-js): keep latest message fetch state - #1050

Open
OskarEichler wants to merge 3 commits into
paypal:mainfrom
OskarEichler:codex/paypal-messages-latest-fetch
Open

OskarEichler wants to merge 3 commits into
paypal:mainfrom
OskarEichler:codex/paypal-messages-latest-fetch

Conversation

@OskarEichler

Copy link
Copy Markdown

Problem

usePayPalMessages can retain a failed fetch error after a later fetch succeeds. Concurrent fetches can also complete out of order, allowing an older empty-content response to overwrite the state of a newer successful request. A request finishing after its session changes can update the current hook for an obsolete session.

Fix

  • Clear the current fetch error when a new request starts.
  • Track monotonically increasing fetch requests and update error state only for the latest active request.
  • Invalidate pending requests when the Messages session changes or is removed.
  • Preserve each caller promise result even when its state update is obsolete.
  • Add separate regressions for successful retry recovery and reversed completion order, plus a patch changeset.

No public API, returned content, or dependency changes are introduced.

Verification

  • Focused usePayPalMessages suite: 18 tests pass.
  • Full React package suite: 72 suites, 918 tests and 17 snapshots pass.
  • Package ESLint and TypeScript pass with five pre-existing JSDoc warnings.
  • Core and all four React package bundles build.
  • Focused Prettier and git diff --check pass.

@OskarEichler
OskarEichler requested a review from a team as a code owner September 1, 2026 05:44
@changeset-bot

changeset-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 883ea89

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

This PR includes changesets to release 1 package
Name Type
@paypal/react-paypal-js 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

await firstFetch;
});

expect(result.current.error).toBeNull();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similar to my comment on PR 1051, can we also assert that the content is the populatedContent?

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