purescript / trypurescript

PureScript in the browser
https://try.purescript.org
BSD 3-Clause "New" or "Revised" License
119 stars 50 forks source link

User-inputted module's `main` call called twice #293

Open JordanMartinez opened 2 years ago

JordanMartinez commented 2 years ago

Opening up https://try.purescript.org/, I see that the module's main function is called twice, again. I thought this was fixed by #279, but maybe the recent es-module-shims update to 1.5.9 broke something?

andys8 commented 2 years ago

In case the issue has its root cause in es-module-shims there are two commits in recent releases that mention "initialization". Maybe interesting.

https://github.com/guybedford/es-module-shims/compare/1.5.9...1.5.12

Update: I don't think this will fix the issue.

I could reproduce the issue in Firefox, but not in Chrome. Could be browser or version related (e.g. one needs shims and the other doesn't).

https://discord.com/channels/864614189094928394/869607074152206397/1007075896005492837

andys8 commented 2 years ago

I think I found the issue:

The docs of es-module-shims have this paragraph:

This execution failure is a feature - it avoids the polyfill causing double execution. The first import being a bare specifier in the pattern above is important to ensure this.

This is not the case for try.purescript.org. Adding import react from 'react'; as the first import would indeed lead to a working example in both Chrome and Firefox.

image

An alternative described in the docs is to activate shimMode.

window.esmsInitOptions = { shimMode: true }

Shim mode is an alternative to polyfill mode and doesn't rely on native modules erroring - instead it is triggered by the existence of any Githubissues.

  • Githubissues is a development platform for aggregating issues.