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 warning without stack for ie9 #13620

Merged
merged 3 commits into from Sep 12, 2018

Conversation

Projects
None yet
7 participants
@link-alex
Contributor

link-alex commented Sep 11, 2018

Where console methods like log, error etc. don't have 'apply' method.
Because of the lot of tests already expect that exactly console['method']
will be called - had to reapply references for console.error method

#13610

@pull-bot

This comment has been minimized.

pull-bot commented Sep 11, 2018

Details of bundled changes.

Comparing: f6fb03e...f785a3d

schedule

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
schedule.development.js n/a n/a 0 B 19.17 KB 0 B 5.74 KB UMD_DEV
schedule.production.min.js n/a n/a 0 B 3.16 KB 0 B 1.53 KB UMD_PROD

Generated by 🚫 dangerJS

const originalConsoleError = console.error;
if (typeof console.error.apply === 'undefined') {
console.error = consoleError;

This comment has been minimized.

@gaearon

gaearon Sep 11, 2018

Member

There are more moving parts here than I'd like.

I'd like to use the same solution for all cases. Can we do that somehow?

The easiest one might just be to switch on args length and explicitly pass them all down.

This comment has been minimized.

@link-alex

link-alex Sep 11, 2018

Contributor

That was my first intention :)
But then I thought that maybe it’s not desired to switch to fixed amount of args.
If it’s ok for you - I can update.

This comment has been minimized.

@gaearon

gaearon Sep 11, 2018

Member

Fixed amount of args is okay. We have that in invariant.

@link-alex

This comment has been minimized.

Contributor

link-alex commented Sep 11, 2018

All the parameters are passed explicitly now, but result looks a bit frustrating for me.. So please have a look, thanks!

@@ -15,8 +15,6 @@
let warningWithoutStack = () => {};
if (__DEV__) {
const consoleError = Function.prototype.bind.call(console.error, console);
warningWithoutStack = function(condition, format, ...args) {

This comment has been minimized.

@gaearon

gaearon Sep 11, 2018

Member

Let’s assert the number of arguments isn’t higher than supported here?

This comment has been minimized.

@link-alex

link-alex Sep 12, 2018

Contributor

As far as I can see the maximum of 8 arguments is used at the moment for this warning. Do you want to add extra check? But how many arguments do we need to check? That's exactly the reason I didn't use this approach initially..

btw, the tests marked as failed, but as I can see on circleci - tests itself passed, but later this happened. Is it related to the change? Or verification job could be just restarted?

Request failed [401]: https://api.github.com/repos/facebook/react/pulls/13620/requested_reviewers
Response: {
"message": "Bad credentials",
"documentation_url": "https://developer.github.com/v3"
}
Error: TypeError: Cannot read property 'repo' of undefined
at GitHub.APIMetadataForPR (/home/circleci/project/node_modules/danger/distribution/platforms/GitHub.js:274:27)
at GitHub. (/home/circleci/project/node_modules/danger/distribution/platforms/GitHub.js:164:39)
at step (/home/circleci/project/node_modules/danger/distribution/platforms/GitHub.js:40:23)
at Object.next (/home/circleci/project/node_modules/danger/distribution/platforms/GitHub.js:21:53)
at fulfilled (/home/circleci/project/node_modules/danger/distribution/platforms/GitHub.js:12:58)
at
at process._tickCallback (internal/process/next_tick.js:189:7)
Danger failed

This comment has been minimized.

@gaearon

gaearon Sep 12, 2018

Member

If 8 is current maximum the let’s check we have at most 8.

This comment has been minimized.

@gaearon

gaearon Sep 12, 2018

Member

Try rebasing to solve the CI issue

@Kovensky

This comment has been minimized.

Kovensky commented Sep 12, 2018

This sounds a bit crazy, but I wonder if Function.prototype.apply.apply(console.error, console, args) would work 🤔

@link-alex

This comment has been minimized.

Contributor

link-alex commented Sep 12, 2018

@Kovensky not really as far as I can see.. but interesting idea.

link-alex and others added some commits Sep 11, 2018

Fix warning without stack for ie9
Where console methods like log, error etc. don't have 'apply' method.
Because of the lot of tests already expect that exactly console['method']
will be called - had to reapply references for console.error method

#13610
pass parameters explicitly to avoid using .apply
which is not supported for console methods in ie9

@gaearon gaearon merged commit 1b2646a into facebook:master Sep 12, 2018

1 check was pending

ci/circleci CircleCI is running your tests
Details
@gaearon

This comment has been minimized.

Member

gaearon commented Sep 12, 2018

Thanks!

break;
default:
throw new Error(
'warningWithoutStack() currently supports at most 8 arguments.',

This comment has been minimized.

@NE-SmallTown

NE-SmallTown Sep 12, 2018

Contributor

Why we need to do this again? I mean, we have done the args.length > 8 check, we won't reach this branch

This comment has been minimized.

@gaearon

gaearon Sep 12, 2018

Member

Not really necessary. Just left here for exhaustiveness of switch. It should never happen.

@lustoykov

This comment has been minimized.

lustoykov commented Sep 12, 2018

@Kovensky, @link-alex

This might be better to remove the switch, based on your idea:

const message = 'Warning: ' + format;
const args = [message].concat(args.map(item => '' + item));
console.error.apply(null, args);

PS. I think the correct syntax for the craziness would be

const arrayArgs = ['message', 'a', 'b', 'c'];
const thisArg = null;

Function.prototype.apply.apply(console.error, [thisArg, arrayArgs]);

@gaearon gaearon referenced this pull request Sep 13, 2018

Merged

Add 16.5.1 changelog #13638

Simek added a commit to Simek/react that referenced this pull request Oct 25, 2018

Fix warning without stack for ie9 (facebook#13620)
* Fix warning without stack for ie9

Where console methods like log, error etc. don't have 'apply' method.
Because of the lot of tests already expect that exactly console['method']
will be called - had to reapply references for console.error method

facebook#13610

* pass parameters explicitly to avoid using .apply
which is not supported for console methods in ie9

* Minor tweaks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment