Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit 09f802b

Browse files
authored
fix(server side rendering): return a value from mock currentRefinement/metadata (#3078)
* WIP: return a value from mock currentRefinement This is required, as transitionState gets called with the return of this; while the value isn't used anywhere really, it will cause an error if configure + currentRefinements is used in SSR context. (longer description to come once test is written) * write a test * remove only
1 parent 225b12f commit 09f802b

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

packages/react-instantsearch-core/src/core/__tests__/createInstantSearchManager.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ describe('createInstantSearchManager', () => {
319319
});
320320
});
321321

322-
describe('results hydratation', () => {
322+
describe('results hydration', () => {
323323
it('initializes the manager with a single index hydrated results', () => {
324324
const ism = createInstantSearchManager({
325325
indexName: 'index',
@@ -387,6 +387,55 @@ describe('createInstantSearchManager', () => {
387387
});
388388
});
389389

390+
describe('metadata hydration', () => {
391+
test('replaces value with a function returning empty search state', () => {
392+
const ism = createInstantSearchManager({
393+
indexName: 'index',
394+
searchClient: createSearchClient(),
395+
resultsState: {
396+
metadata: [
397+
{ stuff: 1, items: [{ stuff: 2, items: [{ stuff: 3 }] }] },
398+
],
399+
rawResults: [
400+
{
401+
index: 'indexName',
402+
query: 'query',
403+
},
404+
],
405+
state: {
406+
index: 'indexName',
407+
query: 'query',
408+
},
409+
},
410+
});
411+
412+
const hydratedMetadata = ism.store.getState().metadata;
413+
414+
expect(hydratedMetadata).toEqual([
415+
{
416+
value: expect.any(Function),
417+
stuff: 1,
418+
items: [
419+
{
420+
value: expect.any(Function),
421+
stuff: 2,
422+
items: [
423+
{
424+
value: expect.any(Function),
425+
stuff: 3,
426+
},
427+
],
428+
},
429+
],
430+
},
431+
]);
432+
433+
expect(hydratedMetadata[0].value()).toEqual({});
434+
expect(hydratedMetadata[0].items[0].value()).toEqual({});
435+
expect(hydratedMetadata[0].items[0].items[0].value()).toEqual({});
436+
});
437+
});
438+
390439
describe('widget manager', () => {
391440
it('triggers a search when a widget is added', async () => {
392441
const searchClient = createSearchClient();

packages/react-instantsearch-core/src/core/createInstantSearchManager.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,17 +618,17 @@ function hydrateMetadata(resultsState) {
618618

619619
// add a value noop, which gets replaced once the widgets are mounted
620620
return resultsState.metadata.map(datum => ({
621-
value() {},
621+
value: () => ({}),
622622
...datum,
623623
items:
624624
datum.items &&
625625
datum.items.map(item => ({
626-
value() {},
626+
value: () => ({}),
627627
...item,
628628
items:
629629
item.items &&
630630
item.items.map(nestedItem => ({
631-
value() {},
631+
value: () => ({}),
632632
...nestedItem,
633633
})),
634634
})),

0 commit comments

Comments
 (0)