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

Migrating to nextjs #7

Open
arielsvn opened this issue Feb 4, 2020 · 14 comments
Open

Migrating to nextjs #7

arielsvn opened this issue Feb 4, 2020 · 14 comments

Comments

@arielsvn
Copy link
Owner

arielsvn commented Feb 4, 2020

Migrating create react app to nextjs

yarn add next

and so it begins

Add .next/ to .gitignore.

Initially I thought I would have to change the directory structure, but next.js supports having the pages directory in src/pages vercel/next.js#8451

Styles and Images

Started to get errors about importing .sass files which are used heavily on refine.bio. This is suported with a plugin

It was also needed for CSS imports https://github.com/zeit/next-plugins/tree/master/packages/next-css

For the svg files the recommended approach is to use babel-plugin-inline-react-svg and import the SVG as react components. However in refine.bio we have been importing them as images, which is maybe more convenient but less efficient.

After some research, I found next-images which seems to address our specific case.

With that the first error appeared :)

image

Other projects/demos

@arielsvn
Copy link
Owner Author

arielsvn commented Feb 4, 2020

TODO

Nice to have

@arielsvn
Copy link
Owner Author

arielsvn commented Feb 4, 2020

Interesting details:

@arielsvn
Copy link
Owner Author

arielsvn commented Feb 4, 2020

@arielsvn
Copy link
Owner Author

arielsvn commented Feb 4, 2020

One of my biggest concerns was the number of URLs that google has discovered but not indexed from our sitemap:

image

Out of the 60,585 that we have there, 37k are being excluded from search results, more than 50%. This is not good, especially because I want to add another million urls with sample pages. That would be the real long tail 🔥

Even with all that, we are getting some traffic from Google which is also our #1 traffic source.

image

Other advantages

Pain Points

  • Routing. It doesn't support state

  • Limited control of code splitting?

@arielsvn
Copy link
Owner Author

arielsvn commented Feb 5, 2020

Redux

Using Redux is tricky, I would have loved to remove it by this point but we have a bunch of code that depends on it. Mainly for our search page and storing the current state of the user's datasets.

From the examples, there seem to be two approaches to include it. Both create higher order components, in one there's a <Provider and a store for each page and the other one creates a single store for the entire App.

One disadvantage of the latter approach is that it disables automatic static optimization for nextjs.

@arielsvn
Copy link
Owner Author

arielsvn commented Feb 5, 2020

History/router

We were using react-router initially on the client side. Next.js has plans to support it, but it's not a priority.


Notes

@arielsvn
Copy link
Owner Author

arielsvn commented Feb 6, 2020

Additional SEO considerations

  • Filters in search should be links
  • Page items in search should be links

@arielsvn
Copy link
Owner Author

arielsvn commented Feb 7, 2020

CSS Styles

  • CRA puts all styles in a single stylesheet while Next.js splits them.

Can global styles only be imported on _app https://nextjs.org/blog/next-9-2#built-in-css-support-for-global-stylesheets RFC: vercel/next.js#8626

Nextjs doesn't work with CSS files in node_modules vercel/next-plugins#70

Started to get this warnings: webpack-contrib/mini-css-extract-plugin#250
facebook/create-react-app#5372 (comment)

They recommend CSS in JS https://nextjs.org/learn/basics/styling-components

Consequently, there are a bunch of practical issues to consider with traditional CSS-file-based styling (especially with SSR), so we suggest avoiding this method when styling for Next.js.
Instead we recommend CSS in JS, which you can use to style individual components rather than importing CSS files.

chunk styles [mini-css-extract-plugin]
Conflicting order between:
 * css ./node_modules/css-loader??ref--6-2!./node_modules/sass-loader/lib/loader.js??ref--6-3!./src/components/Footer/Footer.scss
 * css ./node_modules/css-loader??ref--6-2!./node_modules/sass-loader/lib/loader.js??ref--6-3!./src/components/Button/Button.scss

Also, pages were not rendering correctly when navigating on the client-side:

image

@arielsvn
Copy link
Owner Author

Packages to remove

  • react-helmet
  • react-scripts

@arielsvn
Copy link
Owner Author

arielsvn commented Feb 20, 2020

Sitemap sample

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <sitemap>
        <loc>https://www.refine.bio/sitemap-0.xml</loc>
    </sitemap>
    <sitemap>
        <loc>https://www.refine.bio/sitemap-1.xml</loc>
    </sitemap>
</sitemapindex>
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 
    xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" 
    xmlns:xhtml="http://www.w3.org/1999/xhtml" 
    xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" 
    xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" 
    xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
    <url>
        <loc>https://www.refine.bio/</loc>
        <priority>0.5</priority>
    </url>
    <url>
        <loc>https://www.refine.bio/about</loc>
        <priority>0.5</priority>
    </url>
    <url>
        <loc>https://www.refine.bio/experiments/SRP068364/transcriptional-profiling-through-rna-seq-of-zebrafish-larval-liver-after-exposure-to-biliatresone-a-biliary-toxin</loc>
        <priority>0.8</priority>
    </url>
    <url>
        <loc>https://www.refine.bio/experiments/GSE24528/expression-analysis-of-zebrafish-melanoma-and-skin-from-the-mitf-brafv600e-p53-line</loc>
        <priority>0.8</priority>
    </url>
    <url>
        <loc>https://www.refine.bio/experiments/SRP069839/marker-gene-pathway-discovery-for-polystyrene-particle-toxicity-in-zebrafish-larvae</loc>
        <priority>0.8</priority>
    </url>
</urlset>

@arielsvn
Copy link
Owner Author

Tests

Had some issues mocking fetch

Bigger problems with the integration tests. I need to find a way to https://spectrum.chat/next-js/general/end-to-end-integration-test~74921ed4-2632-410f-93c1-8e3e6407dc1b

@arielsvn
Copy link
Owner Author

arielsvn commented Feb 28, 2020

Optimizing build

Chunking strategy changed with vercel/next.js#7631
Announcement here https://nextjs.org/blog/next-9-2#improved-code-splitting-strategy

By default with Nextjs vs with custom config

image

with custom config

image

cost of javscript suggest splitting large bundles https://v8.dev/blog/cost-of-javascript-2019

@arielsvn
Copy link
Owner Author

Google coverage after deploy

image

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

No branches or pull requests

1 participant