Skip to content

fix: ReferenceError: onScriptComplete is not defined when using HMR o… #7210

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

Merged
merged 2 commits into from
May 28, 2018

Conversation

chris-czopp
Copy link
Contributor

…n Firefox 45

What kind of change does this PR introduce?

bugfix for Firefox 45 and code improvement

Did you add tests for your changes?

no, it's an enhancement covered by existing tests

If relevant, link to documentation update:

N/A

Summary

I've been testing my app on out-dated Firefox (45) and realised the template relies on hoisting (onScriptComplete assigned before its declaration) which is not only a bad practice but it was crashing the bundling.

Does this PR introduce a breaking change?

no, this is just enhancement

@jsf-clabot
Copy link

jsf-clabot commented May 6, 2018

CLA assistant check
All committers have signed the CLA.

@aleen42
Copy link
Contributor

aleen42 commented May 10, 2018

Met the same problem when using Firefox 40, but I have tested that it did not seem the problem of hoisted, as the following snippet has worked under Firefox 40:

(function () {
    console.log(test);
    function test() {}
})();

The real reason is that function onScriptComplete has been declared inside a condition block rather than a function block (As a common sense, functions declaration must be placed at the root of a function block, no-inner-declaration):

if (true) {
    /** throw an error: func is not defined */
    console.log(func);
    function func () {}
}

@alexander-akait
Copy link
Member

@chris-czopp Please accept CLA

@chris-czopp
Copy link
Contributor Author

@aleen42 I rushed too quickly with the conclusions, good to know the root cause of the issue :)
@evilebottnawi I did and then realised my email address in gitconfig is wrong, I changed it and now I'm stuck with the signed CLA and GH check not being able to pick this up...

@alexander-akait
Copy link
Member

@chris-czopp your should rewrite your email in commints

@webpack-bot
Copy link
Contributor

Hi @chris-czopp.

Just a little hint from a friendly bot about the best practice when submitting pull requests:

Don't submit pull request from your own master branch. It's recommended to create a feature branch for the PR.

You don't have to change it for this PR, just make sure to follow this hint the next time you submit a PR.

@aleen42
Copy link
Contributor

aleen42 commented May 15, 2018

@sokra the method in the timeout handler function before has the same problem.

@webpack-bot
Copy link
Contributor

webpack-bot commented May 15, 2018

For maintainers only:

  • This need to be documented (issue in webpack/webpack.js.org will be filed when merged)

@webpack-bot
Copy link
Contributor

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

@aleen42
Copy link
Contributor

aleen42 commented May 21, 2018

And any milestones here?

@alexander-akait
Copy link
Member

@aleen42 will be merged in near future
/cc @sokra

Copy link
Contributor

@aleen42 aleen42 left a comment

Choose a reason for hiding this comment

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

@evilebottnawi There are still problems here

@@ -173,7 +173,6 @@ class JsonpMainTemplatePlugin {
"onScriptComplete({ type: 'timeout', target: script });"
Copy link
Contributor

@aleen42 aleen42 May 21, 2018

Choose a reason for hiding this comment

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

Here has the same question inside the setTimeout handler function, but not fix at all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, however the timeout var is used inside onScriptComplete. If we moved it below we'd have timeout var hoisted... I think it needs to be further refactored.

@alexander-akait
Copy link
Member

/cc @chris-czopp friendly ping

@sokra sokra merged commit 3f183b5 into webpack:master May 28, 2018
@sokra
Copy link
Member

sokra commented May 28, 2018

Thanks, more changes can be done in a separate PR

aleen42 added a commit to aleen42/webpack that referenced this pull request May 29, 2018
revert changes of webpack#7210, and use a varaible declaration outside a condition block instead, according to https://eslint.org/docs/rules/no-inner-declarations
aleen42 added a commit to aleen42/webpack that referenced this pull request May 29, 2018
revert changes of webpack#7210, and use a varaible declaration outside a condition block instead, according to https://eslint.org/docs/rules/no-inner-declarations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants