-
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG 馃悳] Fix Server Rendering on /account
Page
#1675
Conversation
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.
Thanks for taking a look and fixing this @bendvc. Confirmed with manual testing that we no longer see the server error when going to http://localhost:3000/account
. However, I'm seeing this other error in the browser console:
Wonder if the easiest way around this is to use forwardRef()
?
Thanks for spotting that. I have have committed a fix for this issue. |
Signed-off-by: Ben Chypak <bchypak@mobify.com>
packages/template-retail-react-app/app/pages/account/profile.jsx
Outdated
Show resolved
Hide resolved
@@ -107,14 +107,19 @@ const Account = () => { | |||
navigate('/login') | |||
} | |||
|
|||
// Do not render anything in the account page on the server! | |||
if (!onClient) { |
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.
I can't remember if we were always rendering the account page on the server or if it was added by mistake, but by nature all the data that it displays is private customer data and shouldn't be rendered on the client.
So this is one of the isomorphic development problems that you run into here and there. Because you are always a guest on the server you would be redirected to the login page which would be rendered and sent to the client. Upon loading the app on the client, it would see that you are registered and send you to the account page. So you would get this login page > account page flow.
If you leave the code you commented on in, then you simply have nothing rendered, then the account page. Those errors that you see are only ever shown in develop mode and not in production.
But I guess it all depends on what the behaviour was before the introduction of that breaking change.
Do you happen to know what that was?
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.
From my understanding, before the breaking change we would render the static account page on the server and then hydrate once it got to the client. I don't see any logic that prevents server side rendering in the previous version: https://github.com/SalesforceCommerceCloud/pwa-kit/blob/0843abc9c9dd05d3d9f3a4a2aab211dae4940aa9/packages/template-retail-react-app/app/pages/account/index.jsx
Seeing the login page then account page if you're a registered user doesn't seem like good UX, nothing rendered then account page is probably better. If these errors are only shown development and not production, then I think we should leave in that logic to prevent rendering on the server
Co-authored-by: Joel Uong <88680517+joeluong-sfcc@users.noreply.github.com> Signed-off-by: Ben Chypak <bchypak@mobify.com>
Description
There was a regression when doing accessibility work in the following PR. What is happening is that when you load the
/account
page on the server we are actually rendering the page contents, and with the previous change we were using the document object which threw an error.I did 2 things in this PR...
/account
page when on the server.useRef
.Types of Changes
Changes
How to Test-Drive This PR
Scenario 1: Unauthenticated user accesses the account page.
http://localhost:3000/account
Scenario 2: Authenticated user accesses the account page.
http://localhost:3000
Checklists
General
Accessibility Compliance
You must check off all items in one of the follow two lists:
or...
Localization