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

Merged
merged 3 commits into from Sep 12, 2018

Conversation

link-alex
Copy link
Contributor

@link-alex 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
Copy link

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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

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

@link-alex
Copy link
Contributor Author

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Try rebasing to solve the CI issue

@Jessidhia
Copy link
Contributor

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

@link-alex
Copy link
Contributor Author

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

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
which is not supported for console methods in ie9
@gaearon gaearon merged commit 1b2646a into facebook:master Sep 12, 2018
@gaearon
Copy link
Collaborator

gaearon commented Sep 12, 2018

Thanks!

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

Choose a reason for hiding this comment

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

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

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

@lustoykov
Copy link

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]);

Simek pushed a commit to Simek/react that referenced this pull request Oct 25, 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

facebook#13610

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

* Minor tweaks
jetoneza pushed a commit to jetoneza/react that referenced this pull request Jan 23, 2019
* 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants