React-snap: CRA2 compatibility

Created on 3 Oct 2018  路  23Comments  路  Source: stereobooster/react-snap

I was just trying out react-snap with my project. When I open the site I get a lot of these warnings:

The resource http://localhost:8000/static/js/5.f6bab7d8.chunk.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriateasvalue and it is preloaded intentionally.

Are chunks not properly supported, or is this something else?

Thanks!

bug

Most helpful comment

Update: "fixWebpackChunksIssue": false fixes prerendering, but result has awful Time To First Paint, because it contains script tags in the header. CRA2 compatibility needs more work

All 23 comments

I haven't test it with latest CRA2. I only tested it with alpha versions. So yes something can be broken

@stereobooster How will this affect react-snap, that they've started to inline chunks?

They inline first chunk and this is intentional. We need to investigate further what is broken

It seems that fix is (package.json):

"reactSnap": {
  "fixWebpackChunksIssue": false
}

Please test and tell me if it helps

Update Also, try INLINE_RUNTIME_CHUNK=false yarn build

@stereobooster Yup sure seems to help! What exactly was the "fix" meant to do, that disabling helps?

It fixes how webpack chunks are inserted in html in CRA1, it appears they fixed it in CRA2

Ah sweet! Thanks for the quick solution @stereobooster. Much appreciated!

Update: "fixWebpackChunksIssue": false fixes prerendering, but result has awful Time To First Paint, because it contains script tags in the header. CRA2 compatibility needs more work

Does CRA v2.0.5 fix the issue? i.e by adding env var REACT_APP_INLINE_RUNTIME_CHUNK=false

@jasan-s from my quick tests it seems it works

Now the big question, inline scripts vs extra requests, with react-snap.

If someone here is looking for the solution, the environment variable is INLINE_RUNTIME_CHUNK

# package.json
{
  "scripts": {
    "build": "INLINE_RUNTIME_CHUNK=false react-scripts build && react-snap"
  }
}

Source: https://github.com/facebook/create-react-app/blob/master/docusaurus/docs/advanced-configuration.md

Which is correct? REACT_APP_INLINE_RUNTIME_CHUNK or INLINE_RUNTIME_CHUNK

@uxitten if you define it in .env file use REACT_APP_INLINE_RUNTIME_CHUNK if you add it in the build script use INLINE_RUNTIME_CHUNK

@jasan-s thanks, but TimeoutError agian
screen shot 2018-11-12 at 12 14 17 pm

did you also add this "fixWebpackChunksIssue": false react-snap

"reactSnap": {
  "fixWebpackChunksIssue": false
}

yes
this is my dependencies

screen shot 2018-11-12 at 12 16 59 pm

and react-snap config

screen shot 2018-11-12 at 12 18 07 pm

I finally got to this issue. Try this in package.json:

"react-snap": "https://github.com/stereobooster/react-snap.git#crav2",

Run npm i or yarn. Do not use "fixWebpackChunksIssue": false or INLINE_RUNTIME_CHUNK=false.

Released fix in v1.22.0

This throws if you have no devDeps.

/node_modules/react-snap/run.js:15
  devDependencies["react-scripts"] || dependencies["react-scripts"]
                 ^

TypeError: Cannot read property 'react-scripts' of undefined

Fixed in https://github.com/stereobooster/react-snap/pull/312

Is anyone still experiencing this with 1.23.0? My client side app won't hydrate.

Server works fine:
Screen Shot 2020-08-20 at 11 52 53 PM

Client doesn't:

image

// src/index.tsx
import React from "react";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";

import { hydrate, render } from "react-dom";

const rootElement = document.getElementById("root");
console.log("hi!!");

if (rootElement && rootElement.hasChildNodes()) {
  hydrate(<App />, rootElement);
} else {
  console.log("[app] render");
  render(<App />, rootElement);
}
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();

I'm running yarn react-scripts build && yarn react-snap.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ldevalbray picture ldevalbray  路  6Comments

lewisdonovan picture lewisdonovan  路  7Comments

Marcosul picture Marcosul  路  4Comments

jessevdp picture jessevdp  路  8Comments

aheissenberger picture aheissenberger  路  7Comments