question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Dynamic Imports

See original GitHub issue

Is your feature request related to a problem? Please describe. First, I’ve been following this project for a few months now and found it to be exactly what I need for my lit-element web component needs. There’s one thing I think it’s missing, and that’s route based lazy loading of components.

Describe the solution you’d like On route change, it should load an optional developer provided loading component. It should make an asynchronous request for the component associated with the route, then it should replace the loading component with the requested component once the promise is resolved. The additions can be added to the route.ts.

Describe alternatives you’ve considered I considered and demonstrated the use of a higher order component to achieve the same result using lit-redux-router. Although, it isn’t the cleanest way of doing it. The better way is to modify lit-redux-router. I thought it might be helpful to contribute it to you first. Maybe you have a better idea for how to approach this.

Additional context

An example of what two lazy loaded component routes would look like:

import { html, LitElement } from 'lit-element';
import { connectRouter } from 'lit-redux-router';
import store from './store.js';

import '../pages/home/home.js';
import '../components/Loading';

connectRouter(store);

class AppComponent extends LitElement {

  render() {
    const AboutRoute = {
      load: () => import(/* webpackChunkName: "aboutPage" */ '../pages/home/about'),
      loading: 'eve-loading'
    };
    const DocsRoute = {
      load: () => import(/* webpackChunkName: "docsPage" */ '../pages/home/docs'),
      loading: 'eve-loading'
    };

    return html`
      <div>
        <lit-route path="/" component="home-page"></lit-route>
        <lit-route path="/about" component="about-page" lazy="${true}" .loader="${AboutRoute}"></lit-route>
        <lit-route path="/docs" component="docs-page" lazy="${true}" .loader="${DocsRoute}"></lit-route>
      </div>
    `;
  }

}

customElements.define('eve-app', AppComponent);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hutchgrantcommented, Feb 11, 2019

Yea that’s just the example, you don’t have to use webpack chunks. It does however assume the babel dynamic import plugin will be used in the implementation. But that’s optional, for this optional feature. It’s not a dependency for the module.

0reactions
hutchgrantcommented, Feb 14, 2019

That looks good to me, though I still have to test it. That’s way better looking logic than my hacky method.

Also the success and error events should be optional as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript modules: dynamic import() - CanIUse
"Can I use" provides up-to-date browser support tables for support of front-end web ... Loading JavaScript modules dynamically using the import() syntax.
Read more >
Advanced Features: Dynamic Import - Next.js
Dynamically import JavaScript modules and React Components and split your code ... Next.js supports lazy loading external libraries with import() and React ...
Read more >
Dynamic imports - The Modern JavaScript Tutorial
The import(module) expression loads the module and returns a promise that resolves into a module object that contains all its exports. It can...
Read more >
Browser Compatibility of JavaScript modules: dynamic import()
Browser Support for JavaScript modules: dynamic import() · Chrome · Safari · Firefox · IE Internet Explorer · Opera · Edge ...
Read more >
import() - JavaScript - MDN Web Docs - Mozilla
The import() syntax, commonly called dynamic import, is a function-like expression that allows loading an ECMAScript module asynchronously ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found