Git Product home page Git Product logo

Comments (9)

dgieselaar avatar dgieselaar commented on August 10, 2024 1

@neoziro I've got it working with a fork, this is enough: https://github.com/dgieselaar/loadable-components/blob/65ee245f1166a8ed0ab46760821748ce93cba79e/src/loadable.js#L116. Does it make sense?

from loadable-components.

gregberge avatar gregberge commented on August 10, 2024 1

@dgieselaar thanks for this! It looks great!

from loadable-components.

gregberge avatar gregberge commented on August 10, 2024

This is not possible at this time. To do it we need to couple it with Webpack. I will probably do it soon.

from loadable-components.

rajatpharmeasy avatar rajatpharmeasy commented on August 10, 2024

This is necessary if you are splitting your CSS, otherwise there will be FOUC. The <link> tag needs to be included in the server html.

from loadable-components.

dmitru avatar dmitru commented on August 10, 2024

+1. This feature would be VERY useful to have.

from loadable-components.

ricardobrandao avatar ricardobrandao commented on August 10, 2024

I've started thinking about moving from react-loadable to loadable-components today and I really enjoy the async rendering loadable-components provide! However, not being able to prefetch the chunks seems like a deal breaker for me. Is there any reason why you are unwilling to couple to webpack? Since loadable-components already maps the necessary modules (e.g. window.__LOADABLE_STATE__ = {"children":[{"id":"./home.page.js"}]};) it seems like a small step to know which bundles are necessary,

from loadable-components.

gregberge avatar gregberge commented on August 10, 2024

@ricardobrandao it is more complicated than it looks like. Actually it is just an idea and not the real name of the chunk. We need access to webpack stats in order to know which will be the final file. But I am thinking about a rewriting / simplification of Loadable Components with preload support.

from loadable-components.

dgieselaar avatar dgieselaar commented on August 10, 2024

FYI, here's a (gross) snippet that is working w/ my fork (use/edit at your own peril):

import fs from 'fs';
import {
  uniq,
  flattenDeep,
  pickBy,
} from 'lodash';
import getRenderedComponents from './getRenderedComponents';

const records = fs.readFileSync('records.json'); // from webpack's recordsOutputPath

const components = getRenderedComponents();

const chunks = uniq(flattenDeep(
  components.map((component) => {
    return component.modules.map((m) => {
      if (!records.chunks) {
        return [];
      }
      const chunkIds = values(pickBy(records.chunks.bySource, (value, key) => key.endsWith(` ${m}`)));
      const chunkNames =
        Object.keys(pickBy(records.chunks.byName, value => chunkIds.includes(value)));
      return chunkNames;
    });
  })
)).filter(identity);

I get the components I need to load from the route definition (I have a top-down route configuration), but once you have that, you can use this to get the assets from Webpack. Again, gross, and only works with my fork (which I would not recommend using in production unless you're me).

from loadable-components.

gregberge avatar gregberge commented on August 10, 2024

Loadable Components v3 has been released 🎉, and it supports <link rel="preload">!

👉 https://github.com/smooth-code/loadable-components

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.