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
MagentoRouteHandler: correct handling of unknown routes #1495
MagentoRouteHandler: correct handling of unknown routes #1495
Conversation
This pull request is automatically deployed with Now. Latest deployment for this branch: https://pwa-studio-git-fork-mothership-gmbh-1451-magentoroutehandler.mmansoor.now.sh |
|
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.
Code change is nice and concise, and thanks for adding a unit test!
Could you please provide some verification steps though?
Admittedly I'm new to this code but when I navigate to a route that doesn't exist (/junk.html
) I do get a the 404 treatment:
Here it is against the latest develop
: https://magento-venia-develop.now.sh/junk.html
When I navigate to /junk
(without the .html
), I get a much worse un-styled error message:
Not Found
Here that is agains the latest develop
: https://magento-venia-develop.now.sh/junk.
@supernova-at You don't see this error in these cases, because you do initial requests. The initial requests get resolved directly in the upward server, so you get the "not found" shell. Only non-initial route changes get processed by the magento route handler (see linked issue #1454 ). So to force this error, you'd have to include a broken route link somewhere into the app, e.g. I included a broken link on the home page
When you click the link, you'll now see a 404 "That page could not be found. Please try again." from the ErrorView component. Without the changes, it's a 500 "Something went wrong. Please try again." Hit me up when you have further issues testing (I'm also available in the community slack ;)) |
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'm almost 100% sure this is great, and thank you for contributing. Just had one question.
@@ -94,8 +94,12 @@ export default class MagentoRouteHandler extends Component { | |||
route: pathname | |||
}); | |||
|
|||
const { type, id } = resolvedRoute; | |||
// urlResolver query returns null if a route can't be found | |||
if (resolvedRoute === null) { |
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.
This seems to rely on a literal null, and I'm not sure that's guaranteed. Any reason not to just test it for truthiness 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.
@zetlen In all of my tests null was returned, if there was no match, that's why I decided to make it rely on literal null. And I wanted to have these changes as unobstrusive as possible. But I'm also fine with just checking for truthiness. Should I change this?
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, would you mind?
if (resolvedRoute === null) { | |
if (!resolvedRoute) { |
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.
@zetlen Applied your suggested change
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 - thank you!
Description
MagentoRouteHandler now correctly returns NotFound if the urlResolver-Query returns null.
Further description see issue #1454
Related Issue
Closes #1454 .
Verification Steps
RootComponents/CMS/cms.js
:Proposed Labels for Change Type/Package
Checklist: