Skip to content
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

Detect when a library should be added to the import map during live preview #14

Closed
mbostock opened this issue Oct 18, 2023 · 1 comment · Fixed by #101
Closed

Detect when a library should be added to the import map during live preview #14

mbostock opened this issue Oct 18, 2023 · 1 comment · Fixed by #101
Assignees
Labels
bug Something isn’t working

Comments

@mbostock
Copy link
Member

Import maps are static (see WICG/import-maps#92 for context), so when previewing a site, we can’t add a library to the import map after the page has loaded. This results in a broken experience:

TypeError: Failed to fetch dynamically imported module: npm:whatever

A workaround would be to detect in the diff when a library needs to be added to the import map. In this case we would reload the entire page rather than doing an incremental update. (A full reload isn’t ideal, but at least the page will continue working.)

A more involved workaround would be to avoid import maps entirely during live preview, and instead transpile the JavaScript directly to use URLs. This would avoid needing to reload the page. The only wrinkle is that we’d also need to transpile local ES modules, but I expect we’ll probably have to do that anyway if we e.g. want to support FileAttachment in ES modules, too. It’s also kind of a shame because I was excited to use import maps.

@mbostock mbostock added the bug Something isn’t working label Oct 18, 2023
@mootari
Copy link
Member

mootari commented Oct 24, 2023

Perhaps we can adapt the import maps polyfill provided by es-module-shims. resolveAndComposeImportMap can be imported separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn’t working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants