-
Notifications
You must be signed in to change notification settings - Fork 15
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(react|redux): commerce pages in ssr not working #960
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only generate an hash differently. The hash for commerce pages need to be the url instead of query params
@@ -29,7 +29,7 @@ import type { Dispatch } from 'redux'; | |||
const fetchCommercePagesFactory = | |||
(getCommercePages: GetCommercePages) => | |||
( | |||
query: QueryCommercePages, | |||
query: QueryCommercePagesWithSlug, |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our boilerplate is also making use of this, so we would have to update it as well.
|
||
const query = useMemo( | ||
() => ({ | ||
contentTypeCode: ContentTypeCode.ContentPage, | ||
codes: fetchQuery.slug.split('?')[0] as string, | ||
contentTypeCode: isCommercePage |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -2,6 +2,7 @@ import type { CommercePagesRankingStrategy } from '@farfetch/blackout-redux'; | |||
import type { Config, QueryCommercePages } from '@farfetch/blackout-client'; | |||
|
|||
export interface UseCommercePagesOptions extends QueryCommercePages { | |||
slug: string; |
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.
This will be a breaking change as well, can't it be at least defined as optional?
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.
As mentioned before, this is only used by BG and this will fix the commerce pages in this package version
if (!get(model, 'searchContentRequests')) { | ||
return { contents: INITIAL_STATE_CONTENT }; | ||
} | ||
|
||
const { searchContentRequests, slug, seoMetadata, subfolder } = model; | ||
const url = subfolder !== '/' ? slug?.replace(subfolder, '') : slug; | ||
const normalizedUrl = url |
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.
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