Repository navigation
Keep shared codes in the batch and fetch batches wider than one page - #898
Merged
Merged
Conversation
The batch store kept registered codes in a Set, so the first of several components sharing a code removed it on unmount. The next flush dropped the code from the request and the components still mounted lost their data. Codes are now reference counted and leave the batch only with their last consumer. The batched requests in usePrices and useSkus passed no page size, so the API returned its default of 10 records and every code past the tenth stayed empty. The batch is now fetched in chunks of 25 codes with pageSize 25, in parallel, and a chunk that still overflows its page logs a warning. createBatchStore gets its own spec with fake timers, including the cases both bugs slipped through. The wrapper store tests shrink to a wiring check. Fixes #895, #896, #897
✅ Deploy Preview for commercelayer-react-components ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
gciotola
approved these changes
Oct 29, 2026
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 #895, #896, #897.
Shared codes stay in the batch (#896)
createBatchStorenow reference counts its codes (Map<string, number>). A code leaves the next batch only when its last consumer unregisters. Unregistering still never triggers a refetch.Batches wider than one page (#895)
usePricesanduseSkusfetch the standalone batch with the newfetchInChunks: chunks of 25 codes, each requested withpageSize: 25, run in parallel and merged. If a chunk still overflows its page (several prices per SKU), it logs aconsole.warninstead of truncating silently.The batch gets its own SWR key (
["prices", "batch", token, codes]), so the chunked fetcher applies only to the batch path. ManualfetchPrices/fetchSkuscalls send the parameters they're given, as before.Checked against the test org: 30 SKU codes in one request without
pageSizereturn 10 of 30. WithfetchInChunksall 30 come back.Tests (#897)
core-components/src/createBatchStore.spec.ts: tests the factory directly, with fake timers and a fresh store per test. It includes the two cases both bugs got through: an unregistered code is left out of the next batch, and a shared code survives one consumer's unmount. The second test fails against the oldSetbehaviour.pricesBatchStore.test.tsandskusBatchStore.test.tsshrink from 133 lines each to a wiring check.usePrices/useSkusinterceptor tests check that 30 registered codes become two requests of 25 and 5 codes withpageSize: 25.Also renamed
StoreEntry.skuCodestocodes, and the factory doc now notes that every flush refetches the whole batch.Not in this PR
When the SWR key changes,
dataisundefineduntil the new response arrives, so standalone prices briefly blank out when a new one mounts (noted in #896).keepPreviousDatawould fix it, but it also changes whatisLoadingreports, so it's left for a separate change.The
react-hooks-componentslive API tests skip locally because the root.envdoesn't defineVITE_DOMAINand the sales-channel variables. That's unrelated to this change.🤖 Generated with Claude Code