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

ESM Module Identity #1236

Open
marklundin opened this issue Dec 2, 2024 · 2 comments · May be fixed by playcanvas/engine#7161
Open

ESM Module Identity #1236

marklundin opened this issue Dec 2, 2024 · 2 comments · May be fixed by playcanvas/engine#7161
Assignees
Labels
bug Something isn't working

Comments

@marklundin
Copy link
Member

Reporting this here from Discord

Essentially, a module is preloaded with the query string /module.js?id=123. If this is then later imported via user code, it's generally imported explicitly without the id param, ie import "module.js". This creates a new module identity, meaning /module.js?id=123 resolves as an entirely new module. This can cause problems modules containing side-effects.

When a module is preloaded, it should not create a new module identity.

See repro here https://playcanvas.com/project/1280764/overview/import-test

@marklundin marklundin added the bug Something isn't working label Dec 2, 2024
@marklundin marklundin self-assigned this Dec 2, 2024
@Maksims
Copy link
Collaborator

Maksims commented Dec 2, 2024

As I understand there is already pre-processing of script happens? If so, appending id/hash - would be a sufficient path. As it would avoid a need of changing the caching logic for code.
Are import maps used?

@marklundin
Copy link
Member Author

marklundin commented Dec 2, 2024

Yep there is a pre-processing of scripts happening in a SW which maps module.js => module.js?id=123, however this was only being applied to requests originating from user scripts, ie. an explicit import X from module.js. The initial preload step would still load directly from module.js?id=123, meaning from the browsers perspective, these are 2 different url's.

I've submitted a patch which ensures the preload uses the same path as any explicit import paths within scripts.

@marklundin marklundin linked a pull request Dec 2, 2024 that will close this issue
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.

2 participants