简体   繁体   English

IE11承诺奇怪的行为

[英]IE11 promise strange behaviour

We have noticed really strange behaviour in IE11 when starting Aurelia application. 启动Aurelia应用程序时,我们注意到IE11中的行为确实很奇怪。 It occurs only if it is first time you start app in new window/tab AND mouse cursor is NOT in IE window area (for example program is run from command line with given url - which is important scenario for us). 仅当您是第一次在新窗口/选项卡中启动应用程序并且鼠标光标不在IE窗口区域中时(例如,程序是使用给定的url从命令行运行的-这对我们很重要),它才会发生。 Application then stays on index.html with static content but and nothing happens. 然后,应用程序停留在具有静态内容的index.html上,但是什么也没有发生。 Until you move cursor over window... Then magically app continues without any errors and any issues. 直到您将光标移到窗口上为止...然后魔术般地应用程序继续运行,没有任何错误和任何问题。

As far as I could debug, issue occurs when script enters System.import('core-js') promise. 据我所知,脚本进入System.import('core-js')promise时会发生问题。 It happens with or without using bluebird promise. 无论是否使用蓝鸟承诺,都会发生这种情况。

This is body from "index.html". 这是来自“ index.html”的正文。

<script src="jspm_packages/system.js"></script>
<script src="config.js"></script>
<script>
  System.import('core-js').then(function () {
    return System.import('webcomponents.js/MutationObserver');
  }).then(function () {
    return System.import('aurelia-bootstrapper');
  });
</script>

EDIT: 编辑:

I noticed that what helps is to put promise with timeout (at least 1000ms). 我注意到有帮助的是在超时(至少1000毫秒)内承诺。 Do you have any idea if any better solution exists? 您是否知道是否存在更好的解决方案?

<script src="jspm_packages/npm/bluebird@3.3.3/js/browser/bluebird.js"></script>
<script src="jspm_packages/system.js"></script>
<script src="config.js"></script>
<script>
    // IE11 hack for mutation observer/promises error
    var promise = new Promise(function (resolve) {
        window.setTimeout(
            function () {
                resolve();
            }, 1000);
    });

    System.import('core-js').then(function() {
        return System.import('webcomponents.js/MutationObserver');
    }).then(function() {
        return System.import('aurelia-bootstrapper');
    });
</script>

Here is a workaround for the bug which is caused by IE11 mutation observer behavior wrt scheduling. 这是由IE11突变观察者行为与调度引起的错误的变通办法。 This workaround works with bluebird but not other polyfills: 此变通办法适用于bluebird,但不适用于其他polyfill:

 // use timers for scheduling
 Promise.setScheduler(function(fn) { setTimeout(fn); }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM