Conversation
There was a problem hiding this comment.
Pull request overview
Updates this UI library to work with the latest @constructor-io/constructorio-client-javascript, including type updates and test/runtime fetch polyfilling to replace the removed fetch-ponyfill.
Changes:
- Bumped
@constructor-io/constructorio-client-javascriptpeer dependency to^2.77.0. - Updated types to reflect new client-js typings (
VariationsMapResponse,RangeMin/RangeMax,BaseGroupsupport). - Added
whatwg-fetchand configured Jest to polyfillfetchin the jsdom test project.
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/transformers.ts | Expands group transformer input typing to accept BaseGroup in addition to Group. |
| src/types.ts | Aligns public types with updated client-js (VariationsMapResponse, RangeMin/RangeMax). |
| spec/hooks/useCioClient/useCioClient.test.js | Updates test to use a functional fetch mock and relaxes options assertion. |
| jest.config.js | Loads whatwg-fetch for client (jsdom) Jest runs. |
| package.json | Bumps client-js peer dependency and adds whatwg-fetch devDependency. |
| package-lock.json | Lockfile updates reflecting dependency bump and new devDependency. |
Comments suppressed due to low confidence (1)
package.json:65
- With the bump to
@constructor-io/constructorio-client-javascript^2.77.0, the client optionsfetchvalue is now likely expected to be a function (as reflected in the updated useCioClient test). There are still tests passingfetch: 'mock-fetch-fn'(e.g. spec/hooks/useCioPlpProvider/useCioPlpProvider.test.js and related server tests), which may start failing at runtime if the new client validates option types. Update those mocks to use a function (e.g. jest.fn()) or omitfetchwhere it’s not needed.
"peerDependencies": {
"@constructor-io/constructorio-client-javascript": "^2.77.0",
"react": ">=16.12.0",
"react-dom": ">=16.12.0",
"tslib": "^2.4.0"
},
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2b529ff to
ec297a9
Compare
There was a problem hiding this comment.
Code Review
This PR upgrades constructorio-client-javascript from ^2.35.14 to ^2.77.0 and adapts the codebase to the removal of fetch-ponyfill, while improving type accuracy with VariationsMapResponse, RangeMin/RangeMax, and BaseGroup — overall a clean and necessary update with a few issues worth addressing.
Inline comments: 4 discussions added
Overall Assessment:
| @@ -9,6 +9,7 @@ import { | |||
| SearchResponse, | |||
| GetBrowseResultsResponse, | |||
| VariationsMap, | |||
There was a problem hiding this comment.
Important Issue: VariationsMap is still imported and used in RequestConfigs.variationsMap (line 207), so this import is correct and necessary. However, both VariationsMap (request config type) and VariationsMapResponse (response type) now coexist in the imports — consider adding a comment near the RequestConfigs.variationsMap field clarifying the distinction (i.e. VariationsMap is the request shape passed into API calls, while VariationsMapResponse is what comes back in responses). This is subtle and easy to misuse.
| itemName: string; | ||
| variations?: Variation[]; | ||
| variationsMap?: VariationsMap; | ||
| variationsMap?: VariationsMapResponse; |
There was a problem hiding this comment.
Suggestion: The Item.variationsMap field is now correctly typed as VariationsMapResponse (the response shape). This is a breaking change for any consumers that typed this field as VariationsMap. A changelog entry or a note in the PR description about the breaking nature of this type change would help downstream teams upgrading.
| } | ||
|
|
||
| export function transformItemGroups(groups?: Group[]): PlpItemGroup[] { | ||
| export function transformItemGroups(groups?: (Group | BaseGroup)[]): PlpItemGroup[] { |
There was a problem hiding this comment.
Important Issue: transformItemGroups now accepts BaseGroup in addition to Group, but there are no tests covering this new union type input. The existing test suite has zero coverage for transformItemGroups altogether (confirmed by search). A test covering BaseGroup-typed input (which lacks the children/parents arrays that Group has) should be added to avoid silent runtime failures when the API returns a BaseGroup. Please verify that BaseGroup also has children and parents fields — if it does not, the recursive transformItemGroups(itemGroup.children) call at line 215 would fail at runtime.
| segments: ['segment-1', 'segment-2'], | ||
| testCells: { test: 'cell' }, | ||
| fetch: 'mock-fetch-fn', | ||
| fetch: jest.fn(), |
There was a problem hiding this comment.
Suggestion: Changing fetch from 'mock-fetch-fn' (a string) to jest.fn() (an actual function) is the correct fix since the new client-js version likely validates the fetch option is callable. The switch to expect.objectContaining(...) is also appropriate because the new client internals may add extra options. However, the spread ...clientOptions inside objectContaining includes fetch: jest.fn(), which will always pass since objectContaining does not perform deep equality on function references — this is fine for the intent of the test, but the assertion on fetch is now effectively untested. If verifying the fetch override behaviour is important, consider a dedicated assertion like expect(client.options.fetch).toBe(clientOptions.fetch).
Updated
client-jsto the latest. Sincefetch-ponyfillgot removed fromclient-jsI had to bring inwhatwg-fetchas a devDependency similar to how we do it in AC UI library