-
Notifications
You must be signed in to change notification settings - Fork 2
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
NostoProvider: Extract client script loading functionality to a hook #101
Conversation
src/hooks/useClientScriptLoad.ts
Outdated
|
||
if ( | ||
!existingScript || | ||
existingScript?.getAttribute("nosto-language") !== language || |
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 the language check needed?
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.
May need it for markets. I can't say for sure though
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 is a language mismatch check, it makes sense
d73ff7e
to
ee169bb
Compare
src/hooks/useClientScriptLoad.ts
Outdated
// Load Nosto client script if not already loaded externally | ||
if (!isNostoLoaded() && !shopifyMarkets) { | ||
const urlPartial = `/include/${account}` | ||
const script = createScriptElement(urlPartial) |
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.
Here, can we have a check if the client script is already loaded on page and skip this if possible? Or else we could introduce a config flag through which we could skip adding duplicate script tags
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.
In a separate PR also fine
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.
Sure, we have loadScript flag in the WIP PR waiting to be transferred in the next PR. Sorry, I jumped to different topic. That flag was for the externally loaded script. Timo's comment below is the correct one.
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.
there is already a loaded check (isNostoLoaded) and the flag will be introduced in a later PR
src/hooks/useClientScriptLoad.ts
Outdated
|
||
type NostoScriptProps = Pick<NostoProviderProps, "account" | "host" | "shopifyMarkets"> | ||
|
||
export function useClientScriptLoad(props: NostoScriptProps) { |
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.
rename this to useLoadClientScript
or useClientScriptLoader
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.
useLoadClientScript would be my preference
Extracts client script functionality to a useClientScriptLoad hook + minor cleanup