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

CRA2 compatibility #264

Closed
raRaRa opened this issue Oct 3, 2018 · 23 comments
Closed

CRA2 compatibility #264

raRaRa opened this issue Oct 3, 2018 · 23 comments
Labels

Comments

@raRaRa
Copy link

raRaRa commented Oct 3, 2018

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!

@stereobooster
Copy link
Owner

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

@stereobooster stereobooster changed the title CRA2 & chunks CRA2 compatibility Oct 5, 2018
@stereobooster
Copy link
Owner

Probably connected to facebook/create-react-app#5309

@raRaRa
Copy link
Author

raRaRa commented Oct 5, 2018

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

@stereobooster
Copy link
Owner

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

@stereobooster
Copy link
Owner

stereobooster commented Oct 5, 2018

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

@raRaRa
Copy link
Author

raRaRa commented Oct 5, 2018

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

@stereobooster
Copy link
Owner

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

@raRaRa
Copy link
Author

raRaRa commented Oct 5, 2018

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

@stereobooster
Copy link
Owner

stereobooster commented Oct 5, 2018

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

@jasan-s
Copy link

jasan-s commented Oct 15, 2018

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

@stereobooster
Copy link
Owner

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

@raRaRa
Copy link
Author

raRaRa commented Oct 16, 2018

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

@tzi
Copy link

tzi commented Oct 29, 2018

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

@behnammodi
Copy link

behnammodi commented Nov 12, 2018

Which is correct? REACT_APP_INLINE_RUNTIME_CHUNK or INLINE_RUNTIME_CHUNK

@jasan-s
Copy link

jasan-s commented Nov 12, 2018

@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

@behnammodi
Copy link

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

@jasan-s
Copy link

jasan-s commented Nov 12, 2018

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

"reactSnap": {
  "fixWebpackChunksIssue": false
}

@behnammodi
Copy link

behnammodi commented Nov 12, 2018

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

@stereobooster
Copy link
Owner

See this issue for TimeOut #240

@stereobooster
Copy link
Owner

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.

stereobooster added a commit that referenced this issue Nov 19, 2018
x# Please enter the commit message for your changes. Lines starting
stereobooster added a commit that referenced this issue Nov 19, 2018
x# Please enter the commit message for your changes. Lines starting
@stereobooster
Copy link
Owner

Released fix in v1.22.0

@kjkta
Copy link
Contributor

kjkta commented Dec 5, 2018

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 #312

@nandorojo
Copy link

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.

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

No branches or pull requests

7 participants