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

Use of miniKindOf is not ES5-compliant #4089

Closed
embeddedt opened this issue May 22, 2021 · 6 comments
Closed

Use of miniKindOf is not ES5-compliant #4089

embeddedt opened this issue May 22, 2021 · 6 comments

Comments

@embeddedt
Copy link

Prior Issues

None that I could find.

What is the current behavior?

Redux causes my application to crash on some ES5 browsers because of a nested function within an if statement in kindOf.ts. This is not permitted in ES5 and Babel does not seem to provide a transform for this, probably because it would break existing code.

The exact console log is this: SyntaxError: Nested functions cannot be declared in strict mode.

Steps to Reproduce

It's a bit hard to create a live repro case for this, since finding an ES5 browser is difficult nowadays. However, I can provide a gist with my Babel and browserslist configurations as well as a file highlighting the issue.

What is the expected behavior?

Redux should run in an ES5 environment with a standard Babel configuration.

Environment Details

Browser: Midori 0.5.11 on Ubuntu 18.04

@markerikson
Copy link
Contributor

Huh. This is the first I've ever heard that nested functions aren't legal in some cases. Can you point to some kind of a reference for where this restriction is described?

@embeddedt
Copy link
Author

This is the first I've ever heard that nested functions aren't legal in some cases.

Same here until I ran into the error and did some research on it.

Here are some references:

My understanding of this is that ES5 has extremely loose scoping rules. Normally, the function definition would be hoisted out of the if statement, so in strict mode, they chose to prevent confusion by refusing to allow functions to be declared inside if statements.

This error is rarely observed in practice for two reasons:

  • Many ES5 browsers allow this type of declaration, but with an inconsistent scope. Nonetheless, for cases like this the inconsistent scoping probably wouldn't be apparent.
  • ES6 allows this behavior as the scoping rules were changed there, so any browser which supports ES6 won't choke on this code.

@markerikson
Copy link
Contributor

Yeah, definitely a pretty rare edge case :)

tbh this is low priority for me atm, as we're focusing on getting the RTK Query APIs out the door. If you'd like to submit a PR that rearranges the code to make this work as expected, we can look at getting that in.

@zelflod
Copy link

zelflod commented Jul 7, 2021

It can be reproduced in IE10, you'll have an error "SCRIPT1047: In strict mode, function declarations cannot be nested inside a statement or block. They may only appear at the top level or directly inside a function body.". Looking forward to release 4.1.1

@phryneas
Copy link
Member

phryneas commented Aug 3, 2021

Seems to happen in Safari too: https://stackoverflow.com/questions/68635182/safari-error-functions-cannot-be-declared-in-a-nested-block-in-strict-mode
We should probably bump the priority of this one.

@timdorr
Copy link
Member

timdorr commented Aug 3, 2021

Fixed in https://github.com/reduxjs/redux/releases/tag/v4.1.1

@timdorr timdorr closed this as completed Aug 3, 2021
webMasterMrBin pushed a commit to webMasterMrBin/redux that referenced this issue Aug 21, 2021
webMasterMrBin pushed a commit to webMasterMrBin/redux that referenced this issue Aug 21, 2021
webMasterMrBin pushed a commit to webMasterMrBin/redux that referenced this issue Aug 21, 2021
webMasterMrBin pushed a commit to webMasterMrBin/redux that referenced this issue Aug 21, 2021
webMasterMrBin pushed a commit to webMasterMrBin/redux that referenced this issue Aug 21, 2021
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

No branches or pull requests

5 participants