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

fix: schedule should always resolve #91

Closed
wants to merge 2 commits into from
Closed

fix: schedule should always resolve #91

wants to merge 2 commits into from

Conversation

chiaweilee
Copy link

@chiaweilee chiaweilee commented Mar 30, 2023

entry 不为空,递归有问题,程序无法 resolve。
造成 promise 一直处于 pending 状态,引发微前端“白屏”。

function schedule(i, resolvePromise) {
      if (i < scripts.length) {
        var scriptSrc = scripts[i];
        var inlineScript = scriptsText[i];
        exec(scriptSrc, inlineScript, resolvePromise);
        // resolve the promise while the last script executed and entry not provided
        if (!entry && i === scripts.length - 1) {
          resolvePromise();
        } else {
          schedule(i + 1, resolvePromise);
        }
       }
    }

先兜底修复了,确保最终一定会 resolve。
@kuitos

@kuitos
Copy link
Owner

kuitos commented Mar 30, 2023

有 entry 的话这里就会 resolve,不会走到后面

if (scriptSrc === entry) {
noteGlobalProps(strictGlobal ? proxy : window);
try {
// bind window.proxy to change `this` reference in script
geval(scriptSrc, inlineScript);
const exports = proxy[getGlobalProp(strictGlobal ? proxy : window)] || {};
resolve(exports);

@kuitos
Copy link
Owner

kuitos commented Mar 30, 2023

能提供复现仓库吗?这段代码逻辑应该是没问题的,examples 里有 entry 作为最后一个 script 的例子,我们内部也都是最后一个 script 作为 entry 的用法,目前也都没发现问题。

@kuitos
Copy link
Owner

kuitos commented Mar 30, 2023

released v1.14.6

@kuitos kuitos closed this Mar 30, 2023
@chiaweilee chiaweilee deleted the patch-1 branch March 30, 2023 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants