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

Pre-rendered seo #46

Merged
merged 10 commits into from
May 21, 2020
Merged

Pre-rendered seo #46

merged 10 commits into from
May 21, 2020

Conversation

hsab
Copy link
Collaborator

@hsab hsab commented May 20, 2020

Preview Production Build

After a bit of testing with #45 I managed to get great results.
Decided to branch off of master again because I was just fiddling with code in #45. Wanted to make sure that the changes I've made are meaningful and appropriate. This PR is to be considered clean but there are still 2 issues left that I'm trying to solve.

Create React App: Title and Meta Tags
Create React App: Pre-Rendering into Static HTML Files
react-snap
react-helmet
SEO Recipe
react-snap Recipes

For production we just need to update this line to our final domain:

const rootURL = `https://deploy-preview-46--kind-tesla-a088c1.netlify.app`;

Screenshot_20200520_125554
Screenshot_20200520_143102

Performance Metrics

Issues:

Incorrect class assignment to the blobs wrapper

  • Click on an artist.
  • Reload the artist page
  • Click on "Home" from the nav menu
  • Styling is incorrect. Assigned class is style_container__##XX where it should be blobs-wrapper

Lingering "," at the end of root div

<div id="root">
    <div id="app">...</div>
    ","
</div>

Copy link
Collaborator Author

@hsab hsab left a comment

Choose a reason for hiding this comment

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

Some comments and explanations on the code

@@ -3,7 +3,7 @@ import { useHistory } from "react-router-dom";
import config from "src/config";
import paper from "paper";

import style from "./style.module.scss";
import './style-blobs.css';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This managed to fix the styling when the user enters the homepage from and external link or by typing in the address bar.

Copy link
Collaborator

Choose a reason for hiding this comment

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

very strange that this would happen here and not break the other components that use css modules.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah exactly my thought.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't reproduce this. I renamed style-blobs.css to style.module.css, removed blobs- from the style names. and then

import {
  wrapper,
  popover,
} from './style.module.css';

in the index.js and then className={wrapper} etc and the correct styles are being applied. It does appear as style_wrapper__1dMCn but that's just the generated name from the css modules. The content of the class is accurate.

Copy link
Collaborator

Choose a reason for hiding this comment

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

or was this only happening on Production? Just realized that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is happening in production. Also I have temporarily fixed it by removing the class assignment on PageHeader. Have a look at the last commit when you can 7767417

@@ -105,9 +105,9 @@ export default function BlobField({ collapsed = false }) {

return (
<div
className={style.wrapper}
className='blobs-wrapper'
Copy link
Collaborator Author

@hsab hsab May 20, 2020

Choose a reason for hiding this comment

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

Again fixing styling when entering the homepage from an external link or by typing in the address bar. #46 (comment)

ref={wrapperEl}
style={collapsed ? {} : { width: parentWidth, height: parentHeight }}
// style={collapsed ? {} : { width: parentWidth, height: parentHeight }}
Copy link
Collaborator Author

@hsab hsab May 20, 2020

Choose a reason for hiding this comment

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

@@ -122,7 +122,7 @@ export default function BlobField({ collapsed = false }) {
: "NEARREST NEIGHBOR"}
</div>
)}
<div className={style.popover} style={popoverStyle}>
<div className='blobs-popover' style={popoverStyle}>
Copy link
Collaborator Author

@hsab hsab May 20, 2020

Choose a reason for hiding this comment

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

@@ -1,22 +1,22 @@
.wrapper {
.blobs-wrapper {
Copy link
Collaborator Author

@hsab hsab May 20, 2020

Choose a reason for hiding this comment

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

Changing from SASS to pure CSS #46 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

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

did you try this with the modules in place? I'm wondering if it was actually sass that was breaking it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm gonna give it a try and report back.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No success :(

I found:

There's also the following in my console during dev preview:

Warning: Expected server HTML to contain a matching <div> in <div>.
    in div (at App/index.js:10)
    in Router (created by BrowserRouter)
    in BrowserRouter (at App/index.js:9)
    in Unknown (at src/index.js:17)
    in StrictMode (at src/index.js:16)
console.<computed> @ index.js:1

Wondering if this has to do with that lingering "," but figuring it out is way over my head and my react knowledge.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok. i can take a look after the lecture tonight

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hey managed to narrow down the issue to PageHeader component's outermost div. Removing the className on this element fixes the problem. But no matter how hard I tried to add the class back, be it through pure css, having the css in the public folder and linking in html, sass, etc, it kept messing up the bg titles after returning to homepage from an artist page. I hope this helps.

7767417

category,
tags,
twitter,
image: image ? image.images[image.images.length - 1].path : 'FALLBACKIMAGE'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FALLBACKIMAGE needs to be changed to default image later on.

const Comp = lazy(() => import(`../../work/${component}`));
return (
<Route path={`/${slug}`} key={slug}>
<Comp />
<Comp config={config.artists[i]}/>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Passing the config data to the artist component to automatically infer the path and title.

Copy link
Collaborator

Choose a reason for hiding this comment

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

i'm not sure if this will do what is intended. Lazy is used to code split the bundle, so each artist has their own js file instead of loading them all at once. Or is this just to pass the SEO metadata?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is to just pass the SEO data from the config to the component. I'm not sure if what I'm doing is right. But the styling issue existed even when I had the metadata hardcoded with this file unmodified.

Copy link
Collaborator

Choose a reason for hiding this comment

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

weird. lets see how removing sass goes and then i can poke around if you want. If the site is going to be static though you could remove the lazy stuff entirely since it won't help too much.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems like snap supports webpack chunks. Is this what Lazy uses? Based on what I know snap is only semi-static and still depends on being hydrated, generating the most basic html needed for pre-rendering. Wonder if chunks help in this regard. Also glancing over the generated artist htmls I see a lot of xxxxx.chunk.js

@@ -33,6 +33,8 @@ body {
font-family: sans-serif;
font-weight: 700;
line-height: initial;
margin-top: 50vh;
Copy link
Collaborator Author

@hsab hsab May 20, 2020

Choose a reason for hiding this comment

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

Again fixing styling when entering the homepage from and external link or by typing in the address bar. Translation is to accommodate centering in the absence of
style={collapsed ? {} : { width: parentWidth, height: parentHeight }}
#46 (comment)

hsab and others added 2 commits May 20, 2020 16:19
… but this was my first stab and it is slightly cleaner)

adds blob style modules back
blobfield checks for collapsed state via useLocation rather than route callback
reorder blobfield to be before switch
adds wrapper class back to header
removed lazy and suspense (this gave me about 20 more FPS on the blobs!)
@brysonian
Copy link
Collaborator

brysonian commented May 21, 2020

Ok just pushed a bunch and i believe it is fixed. It seemed to be something up with the router. So i shuffled some things there, the main fix was putting blob field at the top and adding useLocation to set the value of collapsed vs a route with a match callback. Seems to all be working now although i can't say 100% that i understand why, which is frustrating.

As a side effect, i removed the code splitting to see if that was causing trouble and got a remarkable increase in speed from that? Possibly some heisenbuggy non-sense, but it was reproducible, and the load trade off is minimal since the chunks are actually much smaller than i anticipated.

No luck on that freaking comma, need to not be on the computer for a while but i'll look again later tonight or more likely in the monring.

@brysonian
Copy link
Collaborator

brysonian commented May 21, 2020

It's always the little things lol 05cb69e#diff-1fdf421c05c1140f6d71444ea2b27638R17

@lmccart
Copy link
Collaborator

lmccart commented May 21, 2020

erp, my bad with the single quotes. now I know!

@brysonian
Copy link
Collaborator

Oh no i was linking to that one line #17, there was a comma in there. The single quotes change i think was hirad and is just personal preference.

@lmccart
Copy link
Collaborator

lmccart commented May 21, 2020

ohh haha I didn't really know how single vs double quotes could result in a comma but the internet never ceases to amaze me

@hsab
Copy link
Collaborator Author

hsab commented May 21, 2020

It's always the little things lol 05cb69e#diff-1fdf421c05c1140f6d71444ea2b27638R17

oh my. that was a leftover from the argument separator to render. Totally missed that one.
Thank you so much for looking into this Chandler and fixing the class assignment issues! I really appreciate it <3

@blerchin
Copy link
Owner

did y'all ever figure out the style issue? if it's only happening on production it probably has something to do with MiniCssExtractPlugin. webpack uses style-loader in development, which injects css via a javascript file and facilitates hot-reloading. In production we'd rather use actual css files so the ExtractPlugin generates flat css files.

@hsab
Copy link
Collaborator Author

hsab commented May 21, 2020

@blerchin yeah chandler managed to fix it. Not sure if we figured out the cause though
5f2e343

@hsab
Copy link
Collaborator Author

hsab commented May 21, 2020

@blerchin @brysonian This looks good to be merged into master.
For production we just need to update this line to our final domain:

const rootURL = `https://deploy-preview-46--kind-tesla-a088c1.netlify.app`;

Also fixed the seo/smo stuff for homepage in the last commit
Screenshot_20200521_131619

Screenshot_20200521_132136

@blerchin
Copy link
Owner

As a side effect, i removed the code splitting to see if that was causing trouble and got a remarkable increase in speed from that? Possibly some heisenbuggy non-sense, but it was reproducible, and the load trade off is minimal since the chunks are actually much smaller than i anticipated.

Fascinating. With code splitting webpack has to duplicate a lot of dependencies so that may have been a source of slowness. Also with static imports it can do some additional optimizations, tree-shaking and stuff. So that might be speeding things up and making the single bundle smaller than expected.

@brysonian
Copy link
Collaborator

re: classnames, i was something in router combined with the hydration. but to find the exact problem would require diving into the guts of those libs

@blerchin
Copy link
Owner

@hsab still getting up to speed with this. I will take a quick look to try to familiarize myself. But excited to have this working!

We may need to remove public/_redirects which causes netlify to always load index.html no matter what file is requested.... Actually I'm surprised the seo is working at all with that in place

@hsab
Copy link
Collaborator Author

hsab commented May 21, 2020

@blerchin
curl https://deploy-preview-46--kind-tesla-a088c1.netlify.app/graham-akins
Shows the proper static index for artist being loaded.

@hsab
Copy link
Collaborator Author

hsab commented May 21, 2020

@blerchin
Copy link
Owner

weird stuff. Well, it's still working without _redirects. In any case, it's good not to depend on proprietary config stuff.

@blerchin
Copy link
Owner

I looked over the diff, and while I don't have a lot of context on this it all LGTM.

@hsab
Copy link
Collaborator Author

hsab commented May 21, 2020

I looked over the diff, and while I don't have a lot of context on this it all LGTM.

If you're going to approve, let me update the link to our master preview.

@blerchin
Copy link
Owner

@hsab when you feel it's ready, you can approve and I'll merge 😏

@hsab
Copy link
Collaborator Author

hsab commented May 21, 2020

@blerchin Should be good now. I can't approve since I'm the PR author.

@blerchin
Copy link
Owner

@hsab oh, I didn't realize that's how it works. I'll approve in that case

@hsab hsab merged commit d741968 into master May 21, 2020
@hsab
Copy link
Collaborator Author

hsab commented May 21, 2020

yaaaaaay!

Screenshot_20200521_134940

Screenshot_20200521_134847

Screenshot_20200521_135005

Screenshot_20200521_135024

Screenshot_20200521_135137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants