Comments (4)
@neoziro I think I found a possible solution:
basically I change the loadComponents()
to this:
function loadComponents() {
if (typeof window === 'undefined') {
throw new Error('loadable-components: loadComponents must be called client-side: window is undefined');
}
return new Promise(function (resolve, reject) {
window.onload = function() {
var state = window[LOADABLE_STATE];
if (!state) {
throw new Error('loadable-components state not found. ' + 'You have a problem server-side. ' + 'Please verify that you have called `loadableState.getScriptTag()` server-side.');
}
resolve(loadState(state));
}
});
}
The function has to wait for the window to be fully loaded and then I have to wrap it in a Promise, in order to return only when the window is loaded.
Do you think this is a bug or do you think I might missing something somewhere?
from loadable-components.
Ah good workaround. In fact loadableState.getScriptTag()
must be called before your loadComponents()
and it should work without having to rewrite the loadComponents
method.
from loadable-components.
Thanks for the reply, I moved the loadableState.getScriptTag()
before importing my main js file and it is working now. By the way, I'm not 100% sure the window is gonna be loaded every time, do you think might be useful to wrap it on a promise and wait for onload
event before resolving the promise?
from loadable-components.
No I don't think so. You should add scripts at the end of the body, this is the way to setup all React stuff so I think it is OK like that.
from loadable-components.
Related Issues (20)
- Preparing users for new lazy component HOT 4
- Add importEntrypoint to CunkExtractor and donβt load stats with require. HOT 9
- Hydration is not working sometimes on some pages HOT 7
- How use it express ssr + react-scripts. How create this file? '../dist/loadable-stats.json' HOT 1
- Loadable not accepting react-p5-wrapper as input HOT 7
- Component types are incompatible with React 18 HOT 2
- Loadable component SSR remote (localhost:port) HOT 2
- lazy typescript definition missing options argument: Expected 1 argument, but got 2 HOT 2
- Can't get `fallback` to display component HOT 3
- What is the best way to prevent failure to load component or catch properly? HOT 7
- getting Uncaught TypeError: Failed to resolve module specifier HOT 1
- loadable/component Synchronously Load Component Failed with Error "Cannot convert undefined or null to object HOT 2
- SassError: Undefined variable HOT 1
- Inline Chunk injection HOT 2
- Not working with latest @loadable/server & @loadable/babel-plugin `v5.16.0` version HOT 4
- How to lazyload a hook? HOT 3
- Fallback behaviour HOT 1
- Main.js is rendered on every page even if I splitted each page into chunks with @loadable/component
- error in ./node_modules/@loadable/component/dist/loadable.esm.mjs HOT 9
- Why ChunkExtractor is required? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loadable-components.