IE11承诺奇怪的行为

时间:2016-02-26 12:02:25

标签: javascript internet-explorer promise bluebird aurelia

我们注意到在启动Aurelia应用程序时IE11中的行为非常奇怪。 只有在第一次在新窗口/选项卡中启动应用程序并且鼠标光标不在IE窗口区域时才会出现(例如,程序是从具有给定URL的命令行运行的 - 这对我们来说是重要的场景)。应用程序然后保留在index.html上的静态内容,但没有任何反应。 直到你将光标移到窗口上......然后神奇的app继续,没有任何错误和任何问题。

据我调试,当脚本进入System.import('core-js')保证时会出现问题。无论是否使用蓝鸟承诺,都会发生这种情况。

这是来自“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>

编辑:

我注意到有用的是将promise设置为超时(至少1000ms)。您是否知道是否存在更好的解决方案?

<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>

1 个答案:

答案 0 :(得分:1)

这是由IE11突变观察者行为w.r.t调度引起的错误的解决方法。此解决方法适用于bluebird但不适用于其他polyfill:

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