create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

Development page blank on first load

Open SampsonCrowley opened this issue 8 years ago • 32 comments

Is this a bug report?

Yes

Did you try recovering your dependencies?

Yes

Environment

just says it's missing app name

Steps to Reproduce

It's definitely something in my project (upgraded from latest 1.x), because a brand new app works. when I first start the development servers, it has the following html:

<body>
    <div id="root"></div>

    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
    
    <script src="https://www.google.com/recaptcha/api.js?render=explicit" async defer></script>
    <script src="/static/js/bundle.js"></script>
    <script src="/static/js/0.chunk.js"></script>
    <script src="/static/js/main.chunk.js"></script>
</body>

The Page comes up blank and react-dev-tools (chrome extension) says this page is not using react It's almost like the JS is never executed

But as soon as I refresh the page, the page works as expected with the following html served (notice chunk 0 is now chunk 1):

<body>
    <div id="root"></div>

    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
    
    <script src="https://www.google.com/recaptcha/api.js?render=explicit" async defer></script>
    <script src="/static/js/bundle.js"></script>
    <script src="/static/js/1.chunk.js"></script>
    <script src="/static/js/main.chunk.js"></script>
</body>

Expected Behavior

It should just load the right chunk the first time

Actual Behavior

It doesn't execute react on the first load

Reproducible Demo

Very confidential app. will try to bring it down to an MVP I can share. in the mean time I would love at least a direction to look in. there are absolutely zero errors in the console

Similar to #4788 and #4757

SampsonCrowley avatar Nov 15 '18 02:11 SampsonCrowley

Anyone have an idea on potential causes?

SampsonCrowley avatar Nov 16 '18 17:11 SampsonCrowley

I actually have the very same problem also in confidential project. Did anyone discovered what is causing the issue?

mlitvaj avatar Nov 23 '18 10:11 mlitvaj

I'm having the same issue and managed to track it down to a process that changes files at the same time that create-react-app boots in dev mode. If the process happens a tiny bit later, it's all good. I don't remember exactly at which point it started happening but it used to work fine in the past.

I made a tiny project that reproduces the issue https://github.com/dariocravero/cra-blank. The process is simulated by a loop in bash that touches src/App.js. Can you check if it does the same for you?

dariocravero avatar Nov 27 '18 22:11 dariocravero

@dariocravero for me the less compiler causes this - i compile the LESS in parallel with running CRA. If i run LESS and CRA in different terminal tabs, it works fine. It worked on CRA v1.* , something must have changed internally in CRA. However since its just in development it's low priority for me to debug and fix.

mlitvaj avatar Nov 27 '18 22:11 mlitvaj

@Kamahl19 I think you just nailed it. Stylus is my CSS processor of choice and it runs in parallel with CRA to generate .css files

SampsonCrowley avatar Nov 28 '18 00:11 SampsonCrowley

having the same problem running node-sass. something must've changed in the compile process.

omerdn1 avatar Dec 02 '18 12:12 omerdn1

@omerdn1 almost definitely. running the same codebase and dev setup on my computer at home (much more powerful in every aspect) doesn't have this issue

SampsonCrowley avatar Dec 04 '18 02:12 SampsonCrowley

i have the same issue after upgrade

andrecrts avatar Jan 08 '19 19:01 andrecrts

Pull request to fix this problem...

https://github.com/facebook/create-react-app/pull/6215

NilsonBertola avatar Jan 17 '19 13:01 NilsonBertola

@NilsonBF How exactly is it fixing this issue? It only changes path on Win, but this issue happens on MacOS as well

mlitvaj avatar Jan 17 '19 13:01 mlitvaj

the problem consists on the built index.html wont find js and css references from static folder

u need to use a dot before the backslash on script and style import

<script src="./static/js/bundle.js"></script> <script src="./static/js/1.chunk.js"></script> <script src="./static/js/main.chunk.js"></script>

NilsonBertola avatar Jan 17 '19 14:01 NilsonBertola

@NilsonBF How exactly is it fixing this issue? It only changes path on Win, but this issue happens on MacOS as well

Updated pull request for macOs solution too

NilsonBertola avatar Jan 17 '19 14:01 NilsonBertola

I'm on Linux, using node-sass and facing the same issue. Why do we need to check the OS? Looks like it's an issue on Win, Mac and Linux as well.

zgorbe avatar Jan 30 '19 08:01 zgorbe

this is not an OS specific issue and really should not be an OS dependent solution..

SampsonCrowley avatar Jan 30 '19 19:01 SampsonCrowley

Pull Requests tests failed on ubuntu, nobody reportes on Ubuntu yet. In a couple of minutes ill test on ubuntu, then commit the edits.

Thanks ubuntu devs. :)

NilsonBertola avatar Jan 30 '19 19:01 NilsonBertola

Updated pull request without OS dependent!

For awhile u guys can change this line in yours projects.

Tell me how its going

NilsonBertola avatar Jan 31 '19 14:01 NilsonBertola

WE are also experiencing the same issue. Keep us updated how its going, if there's a good fix for it.

georgeplaton7 avatar Feb 05 '19 13:02 georgeplaton7

While my pull request is opened, you guys can fix your own node modules...

  • node_modules
    • react-script
      • config
        • path.js

on path.js line 45

broken => envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/'); fixed=> envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : './');

NilsonBertola avatar Feb 08 '19 00:02 NilsonBertola

I ve tried the @NilsonBF 's fix but not works for me,

I m concurrently running postcss cli with watch and react-scripts start on my project.

I ve tried on linux, windows, macos The issue surprisingly happens only on linux:

 "scripts": {
    "start": "yarn run start:tw & yarn run start:cra",

or

 "scripts": {
    "start": "concurrently \"yarn run start:tw\" \"yarn run start:cra\"",

it's solved with adding sleep to delay react-scripts on linux but it's not a proper solution.

 "scripts": {
    "start": "concurrently \"yarn run start:tw\" \"sleep 1 && yarn run start:cra\"",

or

 "scripts": {
   "start": "yarn run start:tw & sleep 1 && yarn run start:cra",

any workaround would be appreciated.

mustafahlvc avatar Feb 26 '19 19:02 mustafahlvc

I think the only %100 fix is to add a flag to the cli for CRA to be able to call another script at boot. it would then be able to guarantee the second script isn't run until CRA is done booting

SampsonCrowley avatar Mar 05 '19 11:03 SampsonCrowley