Skip to content

Enhancements for useApiFetchCallback.#3521

Open
mikaeltomovic wants to merge 2 commits into
developfrom
add/GOOWOO-8-enhancement-for-useapifetchcallback
Open

Enhancements for useApiFetchCallback.#3521
mikaeltomovic wants to merge 2 commits into
developfrom
add/GOOWOO-8-enhancement-for-useapifetchcallback

Conversation

@mikaeltomovic

Copy link
Copy Markdown
Collaborator

Changes proposed in this Pull Request:

Closes GOOWOO-8

Improves the useApiFetchCallback hook with two changes:

Stabilize and memoize returned functions: mergedState is now stabilized via useIsEqualRefValue + useMemo, and reset is wrapped in useCallback. This makes both enhancedApiFetch and reset maintain stable references across renders when their inputs haven't changed, preventing unnecessary re-renders for consumer components and avoiding spurious dependency changes in downstream hooks.

Restrict overwriteOptions to data and query only: The callback returned by useApiFetchCallback is stateful and bound to a specific API endpoint. Allowing arbitrary option overrides at call time (e.g. path, method) creates a misuse vector where the same hook instance could be used to call unrelated endpoints. Limiting overwriteOptions to data (request body) and query (URL parameters) covers the only legitimate dynamic-at-call-time use cases. As part of this change, the five callsites that were passing { parse: false } as an overwrite have been updated to declare parse: false at hook instantiation instead.

Screenshots:

N/A. Internal hook refactor with no UI changes.

Detailed test instructions:

  1. Go through the Merchant Center setup flow and connect a Google MC account. Verify that account connection, URL switching (switch-url-card), and URL reclaiming (reclaim-url-card) continue to work correctly, including the 403 reclaim flow.
  2. Go through the Google Ads account setup flow. Verify that creating or connecting a Google Ads account (useUpsertAdsAccount, useCreateMCAccount, useConnectMCAccount) works without regressions.
  3. Trigger an error state in any of the above flows and confirm that the reset function correctly clears the error, then re-triggering the action works as expected.

Additional details:

A third enhancement was considered, accepting an optional initialData argument to pre-populate the data field of the hook's state. This was not implemented because this capability already exists via the existing initialState second parameter (e.g. useApiFetchCallback( options, { data: someInitialValue } )). Adding a dedicated initialData parameter would duplicate existing API surface without adding new capability, making the hook signature harder to reason about for no gain.

Changelog entry

Dev - Stabilize reset function reference in useApiFetchCallback by wrapping it in useCallback with a memoized mergedState dependency.
Dev - Restrict overwriteOptions argument of useApiFetchCallback callback to data and query properties only.
Dev - Migrate five callsites from passing parse: false via overwriteOptions to declaring it at hook instantiation.

@github-actions github-actions Bot added type: enhancement The issue is a request for an enhancement. changelog: add A new feature, function, or functionality was added. labels Jun 18, 2026
@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 30.76923% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.1%. Comparing base (2975ff8) to head (b7da1d1).
⚠️ Report is 17 commits behind head on develop.

Files with missing lines Patch % Lines
js/src/hooks/useApiFetchCallback.js 33.3% 5 Missing and 3 partials ⚠️
js/src/hooks/useUpsertAdsAccount.js 0.0% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #3521     +/-   ##
=========================================
- Coverage     64.1%   64.1%   -0.0%     
=========================================
  Files          395     395             
  Lines         6773    6781      +8     
  Branches      1720    1723      +3     
=========================================
+ Hits          4342    4344      +2     
- Misses        2170    2173      +3     
- Partials       261     264      +3     
Flag Coverage Δ
js-unit-tests 64.1% <30.8%> (-<0.1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
js/src/hooks/useCreateMCAccount.js 6.2% <ø> (ø)
js/src/hooks/useUpsertAdsAccount.js 52.9% <0.0%> (ø)
js/src/hooks/useApiFetchCallback.js 24.6% <33.3%> (+0.1%) ⬆️
🚀 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.

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

Labels

changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant