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

Refactor create-account route to use appShell to get provided requisite properties #1430

Merged
merged 10 commits into from
Jul 17, 2019

Conversation

sirugh
Copy link
Contributor

@sirugh sirugh commented Jul 10, 2019

Description

The create-account page (and probably other pages) was broken. Upward used index when serving /create-account. index uses generic-shell.mst, which uses default-initial-contents.st, which references assets.svg.logo. This means that anything using default-initial-contents.mst must also include the asset manifest.

Related Issue

Closes #1429.

Verification Steps

  1. Run this PR locally and go to <url>/create-account. It should show the create account page.

Screenshots / Screen Captures (if appropriate)

Image from Gyazo

Proposed Labels for Change Type/Package

  • major (e.g x.0.0 - a breaking change)
  • minor (e.g 0.x.0 - a backwards compatible addition)
  • patch (e.g 0.0.x - a bug fix)

Checklist:

  • I have updated the documentation accordingly, if necessary.
  • I have added tests to cover my changes, if necessary.

@sirugh sirugh added the version: Patch This changeset includes backwards compatible bug fixes. label Jul 10, 2019
@vercel
Copy link

vercel bot commented Jul 10, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://venia-git-fix-create-account-link.magento-research1.now.sh

@sirugh
Copy link
Contributor Author

sirugh commented Jul 10, 2019

@dpatil-magento not sure why this is failing to build -- I ran the failing command locally and it worked. :(

@dpatil-magento
Copy link
Contributor

@sirugh Looks like the backing instance is down. Checking this now - https://venia-cicd-lrov2hi-mfwmkrjfqvbjk.us-4.magentosite.cloud/

@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Jul 10, 2019

Messages
📖 We are currently working on automating the PR metadata checks. Until that time, you may see failures related to labels/description/linked issues/etc even if you have fixed the problem. Failures will persist until the next push (assuming they are fixed).

Generated by 🚫 dangerJS against 8e157a9

zetlen
zetlen previously approved these changes Jul 15, 2019
Copy link
Contributor

@zetlen zetlen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent thank you!

@zetlen zetlen assigned dpatil-magento and unassigned zetlen Jul 15, 2019
@dpatil-magento
Copy link
Contributor

dpatil-magento commented Jul 15, 2019

@sirugh After creating account on https://venia-qbl9lrsc0.now.sh/create-account, I see js error.

image

Also, whats the expected behavior if Customer is already logged in and then access create-account direct URL?
I tried this on Luma .... and it redirects customer to /customer/account/ and does not show /customer/account/create/ (create account page)

cc @soumya-ashok @awilcoxa as its related to UX.

image

@sirugh
Copy link
Contributor Author

sirugh commented Jul 16, 2019

I'll look into the bug @dpatil-magento.

Also it looks like we have two paths to /create-account, one where the user is on the sign-in page and clicks the create account button, and the other where the user navigates directly to the /create-account url. Now that I realize this, I'm not sure what the intended UX was. Do we even want a /create-account page in venia or do we just want users to create via the sidebar/login page? Adding needs-ux label.

@sirugh sirugh added the needs-ux Collaboration and review from UX team is required label Jul 16, 2019
@sirugh sirugh self-assigned this Jul 16, 2019
@dpatil-magento
Copy link
Contributor

@sirugh the /create-account page already exists when guest user place an order and then click on Create Account button.

image

@soumya-ashok
Copy link

@dpatil-magento and @sirugh

First off, I see this as being such an edge case where someone takes the trouble to save the create account URL and then tries to visit it via the URL especially on shopping sites where they really don't want to create an account in the first place unless there's a compelling reason.

However, if we do want to cover this scenario, we could have the following cases for the sign-in/create account experience

If the user has created an account and is signed in, the footer within the main nav. shows that, like in this mockup - https://magento.invisionapp.com/share/KMT00QQH79C
In this case, unless the user signs out of their account, they would not see the sign-in/create account page. If they do try to visit the create account page via URL while signed in, we should probably allow them to create an account with a different email, but if they try to enter the same email as the one they're currently using, then just show the error we already have for that use-case.

If the user has an account but is signed out and visits the create account page, then they should be able to create an account with an email other than the one they're using, and if they try to use the existing email, display the appropriate error.

Does that answer the question?

@sirugh
Copy link
Contributor Author

sirugh commented Jul 16, 2019

@soumya-ashok as @dpatil-magento showed there are two routes to create an account.

  1. Guest makes purchase and clicks Create Account and is redirected to /create-account. This opens the form as the whole page.

  2. User clicks menu hamburger and Sign In and then Create Account. This opens the form on the side menu.

I don't think we're talking about a situation where a user is navigating directly to /create-account via an external link or anything.

@soumya-ashok
Copy link

@sirugh I see. One of the comments above said "navigates directly to the create account URL", so I thought that meant they were going to it outside of the path provided.
Is there a specific reason why the two routes @dpatil-magento specified are different? I had assumed that clicking create account would lead to the form in the side menu.

# An object that returns true if the NODE_ENV environment variable is set
# to 'development'. Used as a test in other configurations in this file.
# Returns false otherwise.
isDevelopment:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused properties, AFAICT.

- matches: request.url.pathname
pattern: '^/create-account'
use: index
use: appShell
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having two routes, index vs appShell or hardcodedAppShell vs urlResolvedAppShell as @zetlen and I discussed, I went with this method in which I re-used the single appShell. The benefit being that I did not have to rewrite much of the foundation that appShell already provides.

const htmlDataset = document.querySelector('html').dataset;
const { imageOptimizingOrigin } = htmlDataset;
// Protect against potential falsy values for `mediaBackend`.
const mediaBackend = htmlDataset.mediaBackend || 'https://backend.test/media/';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a bug identified where mediaBackend was an empty string which destructures as "" instead of being falsy.

TBH I'm not sure why we have a default value here anyways -- seems like it just gets rewritten in the makeUrl code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there shouldn't be a default here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok -- rather than remove the default, @zetlen and I discussed and it is out of scope. That being said we should probably rewrite makeUrl or at least fix this to not need a fallback (ie. console.error and THEN use a default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added a warning if it's falsy to at least indicate a problem.

@sirugh sirugh assigned zetlen and unassigned sirugh Jul 16, 2019
@sirugh sirugh changed the title provide assetManifest to index object for use in generic app shell renders Refactor create-account route to use appShell to get provided requisite properties Jul 16, 2019
@@ -33,11 +33,10 @@ response:
- matches: request.url.pathname
pattern: '^/(graphql|rest)(/|$)'
use: proxy
# Requests to create an account are handled by the top-level 'index'
# object, which returns a generic app shell
# Requests to create an account are handled by the 'appShell' object.
- matches: request.url.pathname
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it's not clear to me why lines 37-39 are required. I would have assumed we could just resolve similar to how we resolve /search.html, but if I remove these lines I get failures like unable to load "<url>/dist/create-account"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you've uncovered an optimization opportunity in the resource definition. Matches are evaluated top to bottom, so we want the hardcoded matches to be above the matches that check urlResolver. When we know ahead of time that the hardcoded URL will not be resolved with urlResolver, we want to avoid evaluating urlResolver, since it's actually placing a graphQL query. There's gotta be a simpler way to do that in the future.

For now, to prevent merge conflicts, let's just move all the match clauses against literal URL paths to the top of the conditional stack, and all the matches against urlResolver under them. That helps us avoid an additional request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, moved.

@dpatil-magento
Copy link
Contributor

@sirugh QA Pass, can be merged once review is approved.

Copy link
Contributor

@zetlen zetlen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just reorder some conditionals to avoid unnecessary urlResolver calls and go forward with it. I realize that this means testing against the same URL patterns in multiple places. We can fix that later. Thanks for all your help.

const htmlDataset = document.querySelector('html').dataset;
const { imageOptimizingOrigin } = htmlDataset;
// Protect against potential falsy values for `mediaBackend`.
const mediaBackend = htmlDataset.mediaBackend || 'https://backend.test/media/';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there shouldn't be a default here.

@@ -33,11 +33,10 @@ response:
- matches: request.url.pathname
pattern: '^/(graphql|rest)(/|$)'
use: proxy
# Requests to create an account are handled by the top-level 'index'
# object, which returns a generic app shell
# Requests to create an account are handled by the 'appShell' object.
- matches: request.url.pathname
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you've uncovered an optimization opportunity in the resource definition. Matches are evaluated top to bottom, so we want the hardcoded matches to be above the matches that check urlResolver. When we know ahead of time that the hardcoded URL will not be resolved with urlResolver, we want to avoid evaluating urlResolver, since it's actually placing a graphQL query. There's gotta be a simpler way to do that in the future.

For now, to prevent merge conflicts, let's just move all the match clauses against literal URL paths to the top of the conditional stack, and all the matches against urlResolver under them. That helps us avoid an additional request.

Copy link
Contributor

@zetlen zetlen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good now.

@zetlen zetlen removed their assignment Jul 17, 2019
@dpatil-magento dpatil-magento merged commit 98eb578 into develop Jul 17, 2019
@sirugh sirugh deleted the fix/create-account-link branch July 25, 2019 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ux Collaboration and review from UX team is required pkg:venia-concept version: Patch This changeset includes backwards compatible bug fixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug]: create-account link doesn't work
5 participants