Giter VIP home page Giter VIP logo

Comments (4)

KrustyC avatar KrustyC commented on May 14, 2024

@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.

gregberge avatar gregberge commented on May 14, 2024

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.

KrustyC avatar KrustyC commented on May 14, 2024

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.

gregberge avatar gregberge commented on May 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.