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.

Full dynamic import using function argument destructuring breaks on production builds

See original GitHub issue

šŸ› Bug Report

For example on a create-react-app, if i use function argument destructuring on a full dynamic import, the props are seen as undefined, only on production build ( probably minifier optimizations going onā€¦ )

Whatā€™s funny is that if i use ā€œlazyā€ instead of ā€œloadableā€ it seems to workā€¦

To Reproduce

Steps to reproduce the behavior:

For example having a Sidebar for each type of user role ( normal and admin for example ) const Sidebar = loadable(({ role }) => import(./${role}));

myRole being ā€œadminā€

const Layout => ( ā€¦ <Sidebar role={myRole}/> ā€¦ )

Expected behavior

if a component called admin.js or a folder admin with index.js exists on that path, it should be loaded, and in factā€¦ on development mode, it is loadedā€¦

on production build ā€œroleā€ inside the import function is undefined.

If i change this: const Sidebar = loadable(({ role }) => import(./${role})); to this: const Sidebar = loadable((props) => import(./${props.role}));

It worksā€¦ using lazy instead of loadable works both ways

Link to repl or repo (highly encouraged)

Please provide a minimal repository on GitHub.

Issues without a reproduction link are likely to stall.

Run npx envinfo --system --binaries --npmPackages @loadable/component,@loadable/server,@loadable/webpack-plugin,@loadable/babel-plugin --markdown --clipboard

Paste the results here:


Iā€™ll add the reproduction link soon as I have more time, sorry

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
theKasheycommented, Jan 15, 2020
  • lazy == React.lazy šŸ˜…
  • arguments seems to display something wrong. Look like these are ā€œmoduleā€ variables.

Anyway, the best way to tackle this problem is to add your case to babel plugin tests cases.

0reactions
stale[bot]commented, May 15, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Experiences with Dynamic Import so far - Meteor forums
I refactored my app a bit to see if I could get the code splitting or dyanamic import working. I did get it...
Read more >
How can I mock the imports of an ES6 module? - Stack Overflow
I've started employing the import * as obj style within my tests, which imports all exports from a module as properties of an...
Read more >
Dynamic imports and code splitting with Next.js
Unlike static imports, dynamic imports work by applying a method known as code splitting. Code splitting is the division of code into variousĀ ......
Read more >
@babel/plugin-proposal-dynamic-import - Package Manager
@babel/plugin-proposal-dynamic-import ... Display full readme Display full readme ... :boom: [Breaking Change]; :eyeglasses: [Spec Compliance]Ā ...
Read more >
Extract Functions Arguments using Destructure in JavaScript
Breaking down the code; Understanding the arguments Object; The term Parameter vs Argument; Rest Parameters vs Arguments object; Arguments best practicesĀ ...
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