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

Commit

Permalink
fix: serialize cache value on hydrate (#2862)
Browse files Browse the repository at this point in the history
It appears the search client cache uses string for values `{ [key: string]: string }`.
When hydrating it for preventing a new request on the client, we need to
serialize the value into a JSON string.

fixes: #2828
  • Loading branch information
tkrugg committed Oct 24, 2019
1 parent 0052b71 commit 3319665
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ describe('createInstantSearchManager', () => {

expect(Object.keys(searchClient.cache)).toHaveLength(1);
Object.keys(searchClient.cache).forEach(key => {
expect(searchClient.cache[key]).toEqual({
expect(typeof searchClient.cache[key]).toBe('string');
expect(JSON.parse(searchClient.cache[key])).toEqual({
results: [
{
index: 'index',
Expand Down Expand Up @@ -146,7 +147,8 @@ describe('createInstantSearchManager', () => {

expect(Object.keys(searchClient.cache)).toHaveLength(1);
Object.keys(searchClient.cache).forEach(key => {
expect(searchClient.cache[key]).toEqual({
expect(typeof searchClient.cache[key]).toBe('string');
expect(JSON.parse(searchClient.cache[key])).toEqual({
results: [
{
index: 'index1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,12 @@ export default function createInstantSearchManager({

client.cache = {
...client.cache,
[key]: {
[key]: JSON.stringify({
results: results.reduce(
(acc, result) => acc.concat(result.rawResults),
[]
),
},
}),
};
}

Expand All @@ -357,9 +357,9 @@ export default function createInstantSearchManager({

client.cache = {
...client.cache,
[key]: {
[key]: JSON.stringify({
results: results.rawResults,
},
}),
};
}

Expand Down

0 comments on commit 3319665

Please sign in to comment.