Skip to content
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

Merged
merged 2 commits into from
Aug 15, 2024

Conversation

nosto-mikpou
Copy link
Contributor

Extracts client script functionality to a useClientScriptLoad hook + minor cleanup


if (
!existingScript ||
existingScript?.getAttribute("nosto-language") !== language ||
Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor

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

@nosto-mikpou nosto-mikpou force-pushed the extract-client-script-to-hook branch from d73ff7e to ee169bb Compare August 15, 2024 08:08
// Load Nosto client script if not already loaded externally
if (!isNostoLoaded() && !shopifyMarkets) {
const urlPartial = `/include/${account}`
const script = createScriptElement(urlPartial)
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

@nosto-mikpou nosto-mikpou Aug 15, 2024

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.

Copy link
Contributor

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


type NostoScriptProps = Pick<NostoProviderProps, "account" | "host" | "shopifyMarkets">

export function useClientScriptLoad(props: NostoScriptProps) {
Copy link
Contributor

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

Copy link
Contributor

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

@nosto-mikpou nosto-mikpou merged commit 6401719 into master Aug 15, 2024
1 check passed
@nosto-mikpou nosto-mikpou deleted the extract-client-script-to-hook branch August 15, 2024 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants