-
Notifications
You must be signed in to change notification settings - Fork 496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cache-hydration): normalize params returned from response #5946
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 3a3c579:
|
@@ -1,4 +1,6 @@ | |||
// @ts-nocheck (types to be fixed during actual implementation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops!
params: request.params, | ||
results[key].rawResults.map((result) => ({ | ||
indexName: result.index, | ||
params: serializeQueryParameters(qs.parse(result.params)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might or might not be right, but in v3 this is how the cache key is computed, also from the parameters, not from the result:
function deserializeQueryParameters(parameters: string) { | ||
return parameters.split('&').reduce<Record<string, any>>((acc, parameter) => { | ||
const [key, value] = parameter.split('='); | ||
acc[key] = value ? decodeURIComponent(value) : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't think it's worth deviating from the design, but instead of decode/encode uri component, we could simplify it and leave params uri encoded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I can't as it's also used in the mocked client.search
which has decoded params, or I'd have to put a boolean argument in serializeQueryParameters
like shouldEncode
. Don't know if it's worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still would like us to look into making sure we pass the params
from server -> client as well to avoid this duplicate work, but that can be done later
(CI failure still to be fixed of course)
Summary
There are discrepancies between how different versions of the search engine serialize query parameters.
This makes it so this caching solution does not work with all engines.
Result
We can normalize the params returned from the request so that it matches the same format as the one used by the search client.