Repository navigation
Premium Analytics: own the status-preserving parse at the data layer fetch boundary - #50885
Merged
Merged
Conversation
Contributor
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Contributor
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 4 files.
1 file is newly checked for coverage.
|
chihsuan
marked this pull request as ready for review
July 29, 2026 04:08
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.
Fixes WOOA7S-1802
Follow-up to #50727, which restored the HTTP status on failed Stats requests with a global
apiFetchmiddleware. This moves that logic to the data layer's own fetch boundary.Proposed changes
stats-proxy-fetch.ts:fetchStatsProxy()requests withparse: false, normalizes the response, and attachesresponse.statuson failure.error-status-middleware.ts, its registration inquery-client-provider.tsx, and theapiFetch.usecapability guard —packages/datano longer touches apiFetch's global middleware chain.Responseshape checkreport-export-fetch.tsalready had, asapi/is-response.ts.fetchStatsProxy/fetchReport, so none of them depend on a global registration.In a shared chain the fix only worked if the app's boot path ran, and on WP 7.0.x it doesn't (#50309) — so #50727 registered at module load, which then needed a
typeof apiFetch.use !== 'function'guard that exists only because unit suites mock the module. That guard goes away here, as do theparse: falseandper_page=-1pass-throughs that only existed to coexist with middlewares we don't control. The already-parsed branch stays: Storybook's report mocks short-circuit with plain data regardless ofparse.One thing to flag: the moved code shape-checks
Responseinstead of usinginstanceof. jsdom has noResponseconstructor, so on the data layer's normal pathinstanceofthrows in every suite — and guarding it withtypeof Response !== 'undefined'would just be the test-shaped conditional this PR removes elsewhere.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
A refactor with no user-facing change, so this is all about confirming nothing regressed.
jetpack test js packages/premium-analytics— 194 suites / 1340 tests pass. The ported status tests are inpackages/data/src/api/__tests__/stats-proxy-fetch-response.test.ts: 401/502/503/504, an HTML 502 that must keep its status despite unparseable JSON, 204, a body carrying its ownstatus, and a non-Responserejection rethrown untouched.pnpm run storybook:devinprojects/js-packages/storybook, then Packages/Premium Analytics/Widgets/SearchTerms — confirms the mocks still intercept and error mapping still reads the status. Default renders rows; Error (permission 403) shows "You don't have access to this data." with no Retry; Error Retryable (no_connection403) shows Retry./jetpack-premium-analytics/v1/proxy/in devtools) and confirm widgets land on the retryable error state instead of retrying a 403 three times.