fix(react|redux): commerce pages in ssr not working#960
fix(react|redux): commerce pages in ssr not working#960richard190m wants to merge 1 commit intomainfrom
Conversation
464f0ce to
ca1a08e
Compare
ca1a08e to
47eab25
Compare
47eab25 to
14a1d68
Compare
14a1d68 to
2429d79
Compare
2429d79 to
8f7947e
Compare
8f7947e to
d0b2abc
Compare
| hash = generateContentHash({ | ||
| contentTypeCode: ContentTypeCode.CommercePages, | ||
| ...query, | ||
| codes: slug, |
There was a problem hiding this comment.
This will make requests for commerce pages containing different query parameters to be indexed on the same entry in the redux store. Is this ok?
There was a problem hiding this comment.
This only generate an hash differently. The hash for commerce pages need to be the url instead of query params
| (getCommercePages: GetCommercePages) => | ||
| ( | ||
| query: QueryCommercePages, | ||
| query: QueryCommercePagesWithSlug, |
There was a problem hiding this comment.
This will be a breaking change, can't you calculate a default value for the slug or at least make it optional?
There was a problem hiding this comment.
Only BG is using the commerce pages of this package version. We can change this an talk to them to implement this
There was a problem hiding this comment.
Our boilerplate is also making use of this, so we would have to update it as well.
| () => ({ | ||
| contentTypeCode: ContentTypeCode.ContentPage, | ||
| codes: fetchQuery.slug.split('?')[0] as string, | ||
| contentTypeCode: isCommercePage |
There was a problem hiding this comment.
I do not understand this approach. Why would the user need to set isCommercePage to true if there is a useCommercePages hook for that?
There was a problem hiding this comment.
Currently, to distinguish from the fetch to commerce pages endpoint directly we use the contentType commercePages and for the request to Serverless API, we use contentType contentPages, to generate the hash
There was a problem hiding this comment.
Ok, but in that case, why not use the useCommercePages hook by itself? I think that this signature is leaking implementation details that the consumer should not have to worry about. In my opinion, the correct solution would be for the serverInitialState to generate entries for both contentTypes in the store so the consumer does not need to worry about this.
What I mean is, the serverInitialState would set an entry for the commercePages and contentPages contentTypes containing the same data. I think they have the same data format so it would work. If that assumption is not correct, then we should adapt the responses from FO to the proper format.
| import type { Config, QueryCommercePages } from '@farfetch/blackout-client'; | ||
|
|
||
| export interface UseCommercePagesOptions extends QueryCommercePages { | ||
| slug: string; |
There was a problem hiding this comment.
This will be a breaking change as well, can't it be at least defined as optional?
There was a problem hiding this comment.
As mentioned before, this is only used by BG and this will fix the commerce pages in this package version
|
|
||
| const { searchContentRequests, slug, seoMetadata, subfolder } = model; | ||
| const url = subfolder !== '/' ? slug?.replace(subfolder, '') : slug; | ||
| const normalizedUrl = url |
There was a problem hiding this comment.
Is this necessary? If json=true is passed, the response returned by FO will not be html, so the application will not be run in this case.
1729a08 to
b9d6190
Compare
Description
Fix commerce pages on server side by:
Dependencies
Checklist
Disclaimer
By sending us your contributions, you are agreeing that your contribution is made subject to the terms of our Contributor Ownership Statement