fix(ui): preserve usePayloadAPI initial data during refresh#17404
Draft
rasitakyol wants to merge 1 commit into
Draft
fix(ui): preserve usePayloadAPI initial data during refresh#17404rasitakyol wants to merge 1 commit into
rasitakyol wants to merge 1 commit into
Conversation
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:
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Preserves
usePayloadAPI'sinitialDataduring the initial render while refreshing it asynchronously in both normal and React StrictMode execution.This adds unit coverage for:
initialDatawithout an unnecessary refetchWhy?
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
initialDataconsistently while still fetching fresh data asynchronously.How?
Removes the initialization guard from the request effect so the existing AbortController-backed refresh always runs.
initialDataremains the hook's initial state and is synchronized separately when it changes. Since the request effect no longer readsinitialData, 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-cacheRelated discussion: #15474