Skip to content

fix(ui): preserve usePayloadAPI initial data during refresh#17404

Draft
rasitakyol wants to merge 1 commit into
payloadcms:mainfrom
rasitakyol:agent/fix-use-payload-api-initial-data
Draft

fix(ui): preserve usePayloadAPI initial data during refresh#17404
rasitakyol wants to merge 1 commit into
payloadcms:mainfrom
rasitakyol:agent/fix-use-payload-api-initial-data

Conversation

@rasitakyol

Copy link
Copy Markdown
Contributor

What?

Preserves usePayloadAPI's initialData during the initial render while refreshing it asynchronously in both normal and React StrictMode execution.

This adds unit coverage for:

  • StrictMode request cleanup and restart
  • Background refresh outside StrictMode
  • Updating changed initialData without an unnecessary refetch
  • Refetching after params, URL, and locale changes

Why?

React StrictMode re-runs effects during development. The existing initialization ref skipped only the first effect setup, so the simulated remount fetched and replaced initialData. Outside StrictMode, the same guard prevented the background refresh entirely.

The expected behavior is to render initialData consistently while still fetching fresh data asynchronously.

How?

Removes the initialization guard from the request effect so the existing AbortController-backed refresh always runs. initialData remains the hook's initial state and is synchronized separately when it changes. Since the request effect no longer reads initialData, it is also removed from that effect's dependency list to avoid redundant requests.

Testing

  • pnpm exec vitest run --project unit packages/ui/src/hooks/usePayloadAPI.spec.ts (4 passed)
  • pnpm run test:unit (1,697 passed, 2 skipped)
  • pnpm run build:ui --force --no-cache
  • Focused UI lint, Prettier, and diff checks

Related discussion: #15474

@rasitakyol

rasitakyol commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

CI note: build, lint, the focused 4-test regression suite, the full 1,697-test unit run, and all other completed suites are passing.

Three unrelated Lexical E2E jobs failed during page setup, before exercising this hook:

  • LexicalListsFeature landed on the “Create your first user” screen on every retry, so the editor locator never existed. The test source itself documents an occasional CI setup/compilation race.
  • LexicalAutosaveBlock timed out waiting for the editor and failed identically on feat: add afterPasswordReset collection hook #17403, whose diff does not touch UI or Lexical.
  • LexicalFullyFeatured reported 15 failures, but every artifact snapshot shows the “Create your first user” screen. Each test failed in its beforeEach while waiting for the editor or account language selector, before any test body or usePayloadAPI behavior ran.

No patch change is indicated by these artifacts. I do not have upstream Actions admin rights to rerun jobs, so a maintainer rerun of the failed E2E jobs would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant