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.

Setting initial route fails when routes have dynamic import

See original GitHub issue

Describe the bug There is a test which shows that initialising a router can be done by pushing a path. We use dynamic imports to lazy load our routes. In combination, this results that the initial route is not set at all. https://github.com/testing-library/vue-testing-library/blob/d628f36b6122e629553d388a9c4953fc5cb2e1ab/src/__tests__/vue-router.js#L29-L31

To Reproduce Change the following line to

{path: '/about', component: () => import('./components/Router/About.vue')},

and run the tests. https://github.com/testing-library/vue-testing-library/blob/d628f36b6122e629553d388a9c4953fc5cb2e1ab/src/__tests__/vue-router.js#L10

Expected behavior I expected that to work right out of the box or with help of waitFor or something… But I did not manage to get it working.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
afontcucommented, Apr 1, 2020

Hi! Thanks for the extensive reporting and for working on this 🤗

I feel too that changing the public render interface to a Promise is a big deal. It would solve, however, several issues I encountered regarding the first “tick”, where stuff in mounted() or created() is not executed until we await one clock tick.

It is a big deal, but I wonder if there’s any workaround on this. I’ll give a look soon and see what I can come up with!

Have a nice day 😄

1reaction
afontcucommented, Jun 16, 2020

I feel the suggestion above is valid enough so that we don’t need to overcomplicate router setup. As mentioned, VTL provides a comfortable way to set up the store and router, but you can always get the Vue instance and use it in your favor.

Thanks for posting this, though! 👍 It’ll be really helpful for anyone else running into issues with dynamic imports.

Closing it up!

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue + nuxt: dynamic import of route pages fails at render
... I solved it by using the same mechanism as nuxt.js default generated router does, wrapping the component dynamic import as follows:
Read more >
React dynamic imports and route-centric code splitting guide
While developing on a local server, all our files are hosted from our computer's port. In React, the port is set to 3000...
Read more >
[SOLVED] - Dynamic import not working - help - Meteor.js forums
This creates a new component everytime the route is rendered. Each re-render results to mount and unmount instead of just updating.
Read more >
Advanced Features: Dynamic Import - Next.js
Dynamically import JavaScript modules and React Components and split your code into manageable chunks.
Read more >
Manually Lazy Load Modules And Components In Angular
Since Angular 8 we can use the browser's built-in dynamic imports to load ... module can be defined in the routing configuration using...
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