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] error on HMR with es6 bundles #5862

Merged
merged 2 commits into from Nov 27, 2017

Conversation

Slashgear
Copy link
Contributor

What kind of change does this PR introduce?

It's a bug fix.

Did you add tests for your changes?

Update test.

If relevant, link to documentation update:

N/A

Summary

We notice a bug in webpack HMR during our spike on creating es6 bundles.

Bug:

  • bootstrap dev bundle containes a this no longer bound to window, so it was undefined.

Fix:

  • Use window instead of this in both scripts templates.

This bug was identifed in #5776

Does this PR introduce a breaking change?

No.

Other information
Fix #5776
Made with @Osirisxxl

@jsf-clabot
Copy link

jsf-clabot commented Oct 20, 2017

CLA assistant check
All committers have signed the CLA.

@webpack-bot
Copy link
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

Copy link
Member

@sokra sokra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

Copy link
Contributor

@lukeapage lukeapage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think you can use window inside a web worker. Getting the global inside a es6 environment is difficult unless you know something about your environment.

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Oct 24, 2017

Web Worker API

workers run in another global context that is different from the current window. This context is represented by a DedicatedWorkerGlobalScope object in the case of dedicated workers (standard workers that are utilized by a single script; shared workers use SharedWorkerGlobalScope).

You can run whatever code you like inside the worker thread, with some exceptions. For example, you can't directly manipulate the DOM from inside a worker, or use some default methods and properties of the window object.

WorkerGlobalScope.self ?

Copy link
Member

@sokra sokra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use self in WebWorker

@webpack-bot
Copy link
Contributor

@Slashgear Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.

@sokra sokra merged commit 801a253 into webpack:master Nov 27, 2017
@sokra
Copy link
Member

sokra commented Nov 27, 2017

Thanks

@liaobin312716
Copy link

Hi, I got an error ReferenceError:Can't find variable:self(http://30.6.61.126:8081/...)

  • Webpack Version: 3.9.1
    But is works when webpack version is 3.8.1.

Then , I compared the compiled bundle file with the last .
version: 3.8.1
image
version: 3.9.1
image

Use self instead of this maybe bring some new problems ?

@jukben
Copy link

jukben commented Dec 2, 2017

Hi @sokra in https://github.com/callstack/haul we use target: webworker in general because Debug JS remotely in React Native Dev tools. So we experienced the same issue as @liaobin312716 when the JS running outside of webworker (self is not defined in iOS/Andorid JS env). When developer enforce "webworker mode" (code running in webworker) for remotely debug everything is fine. Is there anything that we can do about it? Maybe there is some setting how to mock "self" if it' not present in the current environment. var self = self || window would be sufficient. 🙈

We can't change mode on demand, that would result in restarting of Webpack which is time-consuming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet