-
Notifications
You must be signed in to change notification settings - Fork 105
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
Error when combining with react-loadable. #66
Comments
Can you post small example of application. This will help a lot with debugging |
@stereobooster Here you are. https://github.com/judewang/snapshot-issue |
@judewang did you ever find a solution? |
@jasan-s not yet. I stop finding any solutions but try using server side rendering. |
What are you using for SSR? |
@jasan-s Just |
The actual problem here is the thing which is responsible for injecting JS (react-loadable I suppose), it should inject all JS after the last one in document instead of injecting them in head. |
I suppose this one https://github.com/webpack/webpack/blob/b8f181f57fdc33fc8fccd99e07a3684c9fb723d6/lib/JsonpMainTemplatePlugin.js#L105 "var head = document.getElementsByTagName('head')[0];",
this.applyPluginsWaterfall("jsonp-script", "", chunk, hash),
"head.appendChild(script);", Instead it should be something like this: var lastScript = document.scripts[document.scripts.length - 1];
lastScript.parentNode.insertBefore(newNode, lastScript); This needs correspondent ticket in webpack repo |
I have "fix" for this https://github.com/judewang/snapshot-issue/pull/1/files |
The question is: does this thing makes sense. The idea behind loadable and async import is to speed up loading of website, but after pre-renderer it will contain all js files referenced in html - so it will download them one by one in blocking manner and evaluate. Other options
Not sure if first or second option is faster, but third is the slowest. |
why do you think option 3 will be the slowest? Isn't this the only solution where only the script needed for this page are loaded? |
well, we just rendered page - we know what scripts are gonna be rendered anyway. So if we will not preload them, they will be loaded in waterfall manner, this is definitely slower The only tricky case here if your page has different components depending on the screen size, then you need to prerender page for mobile phones. |
@stereobooster so does every chunk get added to the HTML in react-snap? Or only the chunks for the current render.
They'll be loaded simultaneously, but executed sequentially, which is correct. Using
This is starting to wade into dangerous/exciting territory. I've opened #83 to continue the discussion |
only the chunks for the current render.
I mean if we will not use any preload technique, chunks will be downloaded by webpack mechanism, which will kick in only after main will be downloaded and parsed and starts to execute. But I forgot about the case when chunks depend on each other, that is why |
Ohh right of course, Webpack is never going to expect that the data it's asked to lazy-load is already in the DOM, so preload just means that that data can be already on its way when Webpack asks for it. Right? |
Yes. |
Is there any fix for this? |
@gijo-varghese There's a "fix" in the comment above, but you'd better read #66 (comment), too. In our team, now we use Next.js for React app which needs SSR. |
Hi, I followed guide in create-react-app and done code splitting with react-loadable. After deploying my app to server, I found an error in console said
Can't find variable: webpackJsonp
. I then found the problem is that react-snap will overwrite the html but inject chunks inside<head>
, the chunk's content is something likewebpackJsonp(...)
. Since thewebpackJsonp
was defined insidemain.js
andmain.js
is at the bottom of<body>
, that cause the problem.Here's the sample code produced by
npm run build && npm run react-snap
The text was updated successfully, but these errors were encountered: