-
Notifications
You must be signed in to change notification settings - Fork 463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unused static import emitted in addition to dynamic import #6223
Comments
Super catch! Thanks! I'll look into it. |
I can reproduce and confirm only JSX expression triggers the issue. |
I'm not sure how much this has to do with JSX, which might be a red herring. |
There we go: no JSX. A.res: let make = () => React.null
// This triggers the issue
let test = React.null B.res: let test = () => Js.import(A.make) |
I grabbed some time to look and found that this is related to whether the imported module is pure or having side-effects. |
Exactly. Whether the dynamically imported module has side effects or not, should not matter. |
@cknitt Can you try to test with fix? And let me know any time to need to discuss about |
@mununki Thanks a lot for your work! Will test tomorrow. |
@mununki I can confirm that dynamic loading / type reactModule<'a> = {default: React.component<'a>}
@module("react")
external lazy_: (unit => promise<reactModule<'a>>) => React.component<'a> = "lazy"
let lazy_ = factory => lazy_(async () => {default: await factory()})
module DynamicallyImportedComponent = {
let make = lazy_(() => Js.import(DynamicallyImportedComponent.make))
} (+ wrapping in Will look into integrating this in |
Consider the following modules:
A.res:
B.res:
B.res compiles to the following B.bs.mjs with an unused static import of
A
at the top of the file:The unused static import is only emitted when the line
let test = <div />
is present inA.res
.The text was updated successfully, but these errors were encountered: