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 methods of LazyPromise #1059

Merged
merged 1 commit into from
Mar 28, 2018

Conversation

jlfwong
Copy link
Contributor

@jlfwong jlfwong commented Mar 24, 2018

I was running into problems using code splitting, and eventually discovered it was because of a bug in LazyPromise.

If you have code like this:

const foo = import('./foo')
foo.then(() => console.log('1'))
foo.then(() => console.log('2'))

Then I would expect the the file would log both '1' and '2'. Before this fix, it logs only '1', because if the promise executor has already been invoked, then LazyPromise.prototype.then is a no-op, just returning the existing promise.

The fix is to always invoke the appropriate callback, even if the promise has already been executed.

I ran into this issue when doing code splitting because I wanted to eagerly, but asynchronously load a dependency, and then use it later. I suspect this problem will also occur in any situation where a dynamic import() is used in multiple places in a single file.

@jlfwong
Copy link
Contributor Author

jlfwong commented Mar 28, 2018

Thanks for the review, @fathyb! Is there anything else I need to do to get this merged?

@devongovett devongovett merged commit 74438d4 into parcel-bundler:master Mar 28, 2018
@jlfwong jlfwong deleted the jlfwong/fix-lazypromise branch March 28, 2018 20:47
devongovett pushed a commit that referenced this pull request Oct 15, 2018
devongovett pushed a commit that referenced this pull request Oct 15, 2018
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.

3 participants