-
Notifications
You must be signed in to change notification settings - Fork 683
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
Refactor driver usage to improve Venia portability #1217
Refactor driver usage to improve Venia portability #1217
Conversation
This pull request is automatically deployed with Now. Latest deployment for this branch: https://venia-git-zetlen-refactor-router-drivers-for-portability.magento-research1.now.sh |
e6d1d43
to
917853b
Compare
917853b
to
d309335
Compare
"@babel/plugin-transform-runtime": "~7.3.4", | ||
"@babel/runtime": "~7.3.4", | ||
"@babel/plugin-transform-runtime": "~7.4.4", | ||
"@babel/runtime": "~7.4.2", |
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 it's listed in peerDependencies
do we need @babel/runtime
here?
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.
Yeah, for development.
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.
@supernova-at Entries in peerDependencies
aren't installed when you run yarn
(or npm install
). They're needed for tests, though, so we have to list them in devDependencies
as well.
packages/venia-concept/package.json
Outdated
@@ -47,14 +44,14 @@ | |||
"apollo-link-http": "~1.5.11", | |||
"braintree-web-drop-in": "~1.16.0", | |||
"graphql-cli": "~3.0.11", | |||
"graphql-cli-validate-magento-pwa-queries": "~1.0.0", | |||
"graphql-cli-validate-magento-pwa-queries": "~1.1.0-beta.1", |
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.
Was this change for testing purposes or do we actually want to commit it?
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.
For testing. Removing it.
<Route render={() => <Page>{renderRoutingError}</Page>} /> | ||
<Route | ||
render={() => ( | ||
<Page using={{ Route, Router }}>{renderRoutingError}</Page> |
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.
More of a curiosity question: is it possible for the Route
component being rendered here and the Route
being passed in the using
prop to Page
to be different? Would you ever actually want to do that?
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.
It's possible. And honestly it's easier to just drill the props through. <Page />
is its own component and could be used separately by something in the future, so rather than try to make a new ContextProvider and think about all those use cases, I thought props would be simpler code.
@@ -144,6 +145,6 @@ class App extends Component { | |||
[`Page.js`]: https://github.com/magento-research/pwa-studio/blob/master/packages/peregrine/src/Page/Page.js | |||
[`react-router`]: https://github.com/ReactTraining/react-router | |||
[React Context]: https://reactjs.org/docs/context.html | |||
[ErrorView]:t://github.com/magento-research/pwa-studio/blob/master/packages/venia-concept/src/components/ErrorView/errorView.js | |||
[ErrorView]: https://github.com/magento-research/pwa-studio/blob/master/packages/venia-concept/src/components/ErrorView/errorView.js |
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 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.
Assuming my comments don't need to be addressed, 👍
@supernova-at Thanks for reminding me about the beta version I left in there. I removed it and answered your question about passing Route around. I'd love it if you took another look (at this one before my others if possible) :) |
@zetlen Home page does not load https://venia-e2aw4xl3e.now.sh/ console - Uncaught TypeError: Cannot read property 'location' of undefined |
I successfully verified on my local machine. Not sure where the disconnect is there. |
687be44
to
31c2d8b
Compare
…nother app" This reverts commit d309335.
@dpatil-magento I've refactored this to be much simpler. It appears to be working now in staging--please validate if you have the time! @supernova-at @jimbo No more passing the Route and Router pair around. I figured out what was causing the realm mismatch: it was just bad versioning and |
@zetlen Thanks, testing this one now. |
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.
Looks good to me. I've left a couple of comments.
@@ -1,5 +1,5 @@ | |||
export { Query } from 'react-apollo'; | |||
export { Link, Redirect, Route } from 'react-router-dom'; | |||
export { Link, Redirect, Route, Switch, withRouter } from 'react-router-dom'; |
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.
Consider export *
here, maybe? This is such a major dependency—I think whitelisting only some of its exports qualifies as a leaky abstraction.
If a consumer of venia-concept
wanted to import useRouter()
, for example, they'd encounter the same "conflicting context" issues that this change is addressing.
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.
I'd rather export these things one by one to assist in tree shaking.
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.
Yeah, I ordinarily wouldn't recommend export *
for that reason. I think this counts as a serious flaw in this approach, though. If we're not going to export *
, then we should whitelist all of its exports. And we should consider doing the same for the other third-party libraries being exported here as well.
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.
QA Pass.
d18b3d4
to
4284fa1
Compare
…ub.com:magento-research/pwa-studio into zetlen/refactor-router-drivers-for-portability
This PR is a cherry-pick from #1198 to make that PR more digestible.
It is number 3 of 6 in the chain of cherry-picked PRs. It needs to be merged before the next 3:
Description
When trying to use Venia components in a context with another app, it's easy to get React errors claiming you're trying to use a
Link
element without aRouter
in context. This mostly happens because we forgot a couple of spots where we are hardcoding a particular instance of React Router instead of pulling in the instance provided by@magento/venia-drivers
. This PR does the refactoring and prop drilling necessary to pass drivers around, so that an app can share routing with other components.Related Issue
Closes #ISSUE_NUMBER.
Verification Steps
yarn build
is successfulyarn watch:venia
and load up your local Venia in your browser./noexist.html
) and ensure you see the "Something went wrong. Please try again" message.How Have YOU Tested this?
Screenshots / Screen Captures (if appropriate):
Proposed Labels for Change Type/Package
Checklist: