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

[BUG] Using <script type="module"> does not work since v1.0.5 #7

Closed
H-L opened this issue Feb 1, 2024 · 5 comments
Closed

[BUG] Using <script type="module"> does not work since v1.0.5 #7

H-L opened this issue Feb 1, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@H-L
Copy link

H-L commented Feb 1, 2024

Describe the bug
It seems that window.sharedworker is not defined by @okikio/sharedworker/lib/index.js anymore.
Console will return an error like : TypeError: Right side of assignement cannot be destructured.

I had the error on an "old" Safari 15.6 browser.

  • Script is working correctly at v1.0.4 but breaks at v1.0.5 on this particular use case.
  • It seems the way the script is compiled into /lib has changed, and does not have the necessary code to support older browser.

To Reproduce
Load the script using <script type="module"> tags exactly as described in the README:

<script src="https://unpkg.com/@okikio/sharedworker" type="module"></script>
<script type="module">
    // You can then use it like this
    const { SharedWorkerPolyfill: SharedWorker } = window.sharedworker; 
</script>

Console will return an error like : TypeError: Right side of assignement cannot be destructured.

Expected behavior
Loading the umd script as described in the docs works, and window.sharedworker is defined once @okikio/sharedworker/lib/index.js or https://unpkg.com/@okikio/sharedworker is loaded.

@H-L H-L added the bug Something isn't working label Feb 1, 2024
@H-L
Copy link
Author

H-L commented Feb 1, 2024

Only "Fix" I found comes from this tsup opened issue. It seems this bundler does not support umd yet, but there is a workaround using esbuild (used by tsup).

egoist/tsup#924 (comment)

@okikio
Copy link
Owner

okikio commented Feb 1, 2024

Thanks for bring the issue to my attention I'll draft a fix for it quickly

okikio added a commit that referenced this issue Feb 1, 2024
Signed-off-by: Okiki <okikio.dev@gmail.com>
okikio added a commit that referenced this issue Feb 1, 2024
github-actions bot pushed a commit that referenced this issue Feb 1, 2024
## [1.0.7](v1.0.6...v1.0.7) (2024-2-1)

### Bug Fixes

* add back support for umd [#7](#7) ([3f1a376](3f1a376))
@okikio
Copy link
Owner

okikio commented Feb 1, 2024

This should now be fixed, but please use <script src="https://unpkg.com/@okikio/sharedworker"></script> remove type module from the import, I'll have to update the docs sorry, for the inconvenience, here's a demo https://codepen.io/okikio/pen/qBvoygR?editors=1111

@H-L
Copy link
Author

H-L commented Feb 2, 2024

Thanks a lot for your quick reaction !

Just tried the v1.0.7 on the same Safari 15.6 and the bug is fixed, using the index.umd.js version.

@okikio
Copy link
Owner

okikio commented Feb 2, 2024

Awesome 👌

@okikio okikio closed this as completed Feb 2, 2024
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

No branches or pull requests

2 participants