-
Notifications
You must be signed in to change notification settings - Fork 122
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
Make StorefrontPreview Component Accept Children #1508
Conversation
Make the StorefrontPreview component a wrappable component. This way we can add providers in the future in order to allow for advanced features. E.g. components that are aware of the current context.
|
So we had a conversation in the sync meeting about this and most of use were on board with moving it. But lets talk about these points a little more.
|
To render the Storefront Preview customers would already need to update both the pwa-kit-react-sdk@3.2.0 and commerce-sdk-react@1.0.3 packages to consume the fixes that we made for Storefront Preview. Although the changes made in the SDK were necessary for Storefront Preview to work, they can also be used outside the context of Storefront Preview:
|
Thanks for looking at those other sdk changes.. I feel like none of them warrant us to leave the preview component in the SDK. They all can changes that can stand on their own. |
@@ -17,9 +18,10 @@ import {useHistory} from 'react-router-dom' | |||
* This flag only applies if storefront is ran in Runtime Admin iframe. | |||
* @param {function(): string | Promise<string>} getToken - A method that returns the access token for the current user | |||
*/ | |||
export const StorefrontPreview = ({enabled = true, getToken}) => { | |||
export const StorefrontPreview = ({children, enabled = true, getToken}) => { |
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.
Since we're already export default StorefrontPreview
, then we don't need to export this one too.
export const StorefrontPreview = ({children, enabled = true, getToken}) => { | |
const StorefrontPreview = ({children, enabled = true, getToken}) => { |
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.
The names export is needed for the re-export in the index file. That wasn't a mistake.
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.
Ah ok, TIL.
Description
In this PR we make the StorefrontPreview component a wrappable component. Meaning instead of just plopping it on the page in the app we wrap the content of the application with this component. I'm proposing that we do this for a coupl reasons. First in the future we might want to add Context and Providers to the implementation so components wrapped by it can read the current storefront preview context. We might want to do this if there is a situation where component in the template have some sort of special rendering when Storefront preview is active. Secondly if we don't make this change now, we would have to communicate this change with anyone that adopted StorefrontPreview already that they need to change how they used the component. (Not a huge deal, but it could be annoying) Note this wouldn't be a breaking change for our template if we don't do this now.
Should we move this component into the Commerce-SDK-React project for v3? We adopted the pattern of adding commerce related components to that lib with ShopperExperience, so I think we should follow suit with this API component.