preact-cli: Promise polyfill is not applied

Apps created via cli do not work on browsers without Promise implementation. For Windows users the easiest way to reproduce is to open https://clidemo.preactjs.com in IE11 and look into dev console.

This is problems occurs because of polyfills reside in separate chunks - which would be fine if webpack didn’t use Promises in chunk loading code 😆 (which it does and states so in docs).

I’m thinking we can go several ways:

  • drop non ES2015 browsers support (which means dropping PhantomJS and possibly large part of potential cli users)
  • load promise polyfill eagerly
  • load promise polyfill via some custom JS code (dynamic script tag?)

Steps to reproduce

  1. preact create app
  2. cd app
  3. npm run serve
  4. Visit localhost:8080 in browser without ES6 support
  5. Click any navigation link (e.g. Profile)

Expected result:

  • Page is changed

Actual result:

  • Nothing happens. Error Promise is not defined is seen in console

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (14 by maintainers)

Most upvoted comments

Was there any resolution on this? @thangngoc89, I’m developing for UC as well and am currently just importing and initializing promise-polyfill in my app.js, which obviously feels ridiculous given that it’s sitting in the polyfills chunk already.

@thangngoc89 Correct, but in the majority case, Promise is supported already. A conditional tag (as provided) will load before the webpack runtime, which means Promise will always be ready.

@developit good call I haven’t thought about that fetch requires promise implementation.

@developit @rkostrzewski Instead of a defaultAttribute across the board, we can specify a pattern to match everything except ~ promise.polyfill.js (or whatever name).

Also, I would assume that this script be loaded under a HTML conditional:

<!--[if IE]>
 <script src='promise.polyfill.js'></script>
<![endif]-->