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

[BUG] Missing onContextChange callback for version 2.8 #1766

Open
denchev opened this issue Apr 29, 2024 · 1 comment
Open

[BUG] Missing onContextChange callback for version 2.8 #1766

denchev opened this issue Apr 29, 2024 · 1 comment
Labels
Acknowledged Team has responded to issue

Comments

@denchev
Copy link

denchev commented Apr 29, 2024

Summary

The StrorefrontPreview component is supposed to receive a few arguments one of which is onContextChange callback. For version 2.8 the passed callback is ignored and it is not passed to the window.STOREFRONT_PREVIEW object. That's because it is not present in the list of properties for the StorefrontPreview component in pwa-kit-react-sdk (https://github.com/SalesforceCommerceCloud/pwa-kit/blob/release-2.8.x/packages/pwa-kit-react-sdk/src/ssr/universal/components/storefront-preview/index.jsx)

The version 3 of the component has the onContextChange as property though

I needed the callback so I created a workaround. Added in app/components/_app/index.jsx

useEffect(() => { if (typeof window !== 'undefined' && detectStorefrontPreview()) { window.STOREFRONT_PREVIEW.onContextChange = (context) => { console.log('Force onContextChange for 2.8', context) handleContextChange(context) } } }, [])

This workaround works when deployed to MRT.

The documentation clearly says that this callback can be passed when setting it up for version 2.8. Which leads me to believe that the missing onContextChange in version 2.8 is a bug.

I see two options:

  1. Add the callback to the STOREFRONT_PREVIEW props.
  2. Remove the onContextChange from the documentation for version 2.8

But since it works on MRT, I think it is better to go with 1)

Steps To Reproduce

Pass onContextChange callback with simple console.log
Set preview options from Managed Runtime

Expected result

See the console.log in the browser console showing that callback is called.

Actual result

Nothing happens.

System Information (as applicable)

Browser: Any
Node version: Any
pwa-kit version: 2.8.2
Desktop OS: Any
Mobile Device Info: Any

Additional information

@vcua-mobify vcua-mobify added the Acknowledged Team has responded to issue label Apr 29, 2024
@vcua-mobify
Copy link
Contributor

Thanks for letting us know about this @denchev. I'll add a ticket for us to follow up on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Acknowledged Team has responded to issue
Projects
None yet
Development

No branches or pull requests

2 participants