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

Issue/#19545 #19584

Merged
merged 6 commits into from
Aug 12, 2020
Merged

Issue/#19545 #19584

merged 6 commits into from
Aug 12, 2020

Conversation

pfongkye
Copy link
Contributor

@pfongkye pfongkye commented Aug 11, 2020

Summary

Fixes #19545
The data.name in a given payload should not be a function since window.postMessage would throw an error.

If I'm on the right path, should we modify formatDataForPreview to take into consideration the fact that data.name can be an anonymous function?
image

Test Plan

  • Tests to be added

@facebook-github-bot
Copy link

Hi @pfongkye!

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.

In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 11, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 93543e0:

Sandbox Source
React Configuration
distracted-wozniak-q8kdb Issue #19545

@sizebot
Copy link

sizebot commented Aug 11, 2020

No significant bundle size changes to report.

Size changes (experimental)

Generated by 🚫 dangerJS against 93543e0

@sizebot
Copy link

sizebot commented Aug 11, 2020

No significant bundle size changes to report.

Size changes (stable)

Generated by 🚫 dangerJS against 93543e0

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

2 similar comments
@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Comment on lines +155 to +157
typeof data.name === 'function' || !data.name
? 'function'
: data.name,
Copy link
Contributor

Choose a reason for hiding this comment

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

The javascript Proxy wraps the name attribute. I think instead of using data.name you can replace it by data.prototype.constructor.name. It is the same thing but the difference is the constructor.name is not wrapped by the proxy.

Copy link
Contributor

Choose a reason for hiding this comment

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

The javascript Proxy wraps the name attribute.

Oh that's very interesting! Nice find.

I think instead of using data.name you can replace it by data.prototype.constructor.name. It is the same thing but the difference is the constructor.name is not wrapped by the proxy.

I'm wary of using data.prototype.constructor.name because not all objects have a prototype (e.g. Object.create(null)

@bvaughn
Copy link
Contributor

bvaughn commented Aug 11, 2020

If I'm on the right path, should we modify formatDataForPreview to take into consideration the fact that data.name can be an anonymous function?

Yes. Sounds worth doing.

@bvaughn bvaughn self-assigned this Aug 11, 2020
@pfongkye
Copy link
Contributor Author

@bvaughn I had some tests failing before the modifications. I fixed some. There are two remaining. I wanted to check with you if these are the new expected behaviors before fixing them:
snapshot failing
expecting 3 but received 1

@@ -403,13 +403,13 @@ describe('InspectedElementContext', () => {

expect(targetRenderCount).toBe(1);
expect(errorSpy).toHaveBeenCalledTimes(1);
expect(errorSpy).toHaveBeenCalledWith('error');
expect(errorSpy).toHaveBeenCalledWith('Warning: error');

Choose a reason for hiding this comment

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

Umm.. does Warning: error look okay? The only tests failing in CircleCI belong to this specific commit (args prefixed with "Warning: ").

@bvaughn
Copy link
Contributor

bvaughn commented Aug 12, 2020

@pfongkye I'm not sure I understand what you're asking about those two tests. How do they fail? Hard for me to say if the failure would be expected or not without having more context. The second one in particular though (expected 3 but got 1) does not seem expected, I think.

@@ -43,7 +43,7 @@ describe('Bridge', () => {
jest.runAllTimers();
expect(wall.send).not.toHaveBeenCalled();
expect(console.warn).toHaveBeenCalledWith(
'Cannot send message "should not send" through a Bridge that has been shutdown.',
'Warning: Cannot send message "should not send" through a Bridge that has been shutdown.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you adding "Warning:" prefixes to these tests?

@pfongkye
Copy link
Contributor Author

@pfongkye I'm not sure I understand what you're asking about those two tests. How do they fail? Hard for me to say if the failure would be expected or not without having more context. The second one in particular though (expected 3 but got 1) does not seem expected, I think.

Sorry. So I don't know why but I was having those two tests failing on my computer (OS is Windows 10 Professional):
image
image

But after running build-for-devtools, I'm still having the following test failing:
image

I'm going to revert commit pfongkye@6b36d98#diff-ab5ee5655b2aac3260e1f836546a13c9 and hopefully find out why the tests are failing.

@bvaughn
Copy link
Contributor

bvaughn commented Aug 12, 2020

FWIW, I checked out your branch and reverted that commit locally– and when I ran DevTools tests, they all passed.

Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

This looks like a nice improvement to me. Let's see if CI is happy 😄

Any other changes you looking to include? (I see the PR is still in "Draft" status)

@pfongkye
Copy link
Contributor Author

pfongkye commented Aug 12, 2020

Any other changes you looking to include? (I see the PR is still in "Draft" status)

Nope. It was because of the tests :)

@pfongkye pfongkye marked this pull request as ready for review August 12, 2020 15:47
Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

Looks good to me, thank you!

@bvaughn bvaughn merged commit b6e1d08 into facebook:master Aug 12, 2020
@pfongkye
Copy link
Contributor Author

Thanks a lot!
Guess I'll have to run the tests in docker (or maybe on WSL2) next time 😅

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.

Bug: Proxy on Context throws an error in DevTools
7 participants