You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Add the callback to the STOREFRONT_PREVIEW props.
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
The text was updated successfully, but these errors were encountered:
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
pwa-kit/packages/commerce-sdk-react/src/components/StorefrontPreview/storefront-preview.tsx
Line 30 in 94af623
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:
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
The text was updated successfully, but these errors were encountered: