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 for #6062 : Show source line number on unknown property warning #6398

Merged
merged 8 commits into from
May 3, 2016

Conversation

troydemonbreun
Copy link
Contributor

Fix for #6062

Let me know if I'm off base by using this approach.

(in trying to rebase with a merge conflict, I created commit noise, sorry)

Thanks!

@@ -651,6 +652,9 @@ ReactDOMComponent.Mixin = {
markup = DOMPropertyOperations.createMarkupForCustomAttribute(propKey, propValue);
}
} else {
if (__DEV__) {
ReactDOMInstrumentation.debugTool.onCreateMarkupForProperty(propKey, propValue, this._currentElement);
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is the main one that concerns me. It seems like this call should be inside createMarkupForProperty such that it gets invoked whenever anyone calls it will get the onCreateMarkupForProperty event. However, we should not be passing the element to createMarkupForProperty.

Thus, why this PR is difficult, thus my comments in #6062 (comment) and #6062 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I didn't realize that operation was called directly. I've another
approach in mind as well, I'll try it out next week.
On Apr 1, 2016 6:35 PM, "Jim" notifications@github.com wrote:

In src/renderers/dom/shared/ReactDOMComponent.js
#6398 (comment):

@@ -651,6 +652,9 @@ ReactDOMComponent.Mixin = {
markup = DOMPropertyOperations.createMarkupForCustomAttribute(propKey, propValue);
}
} else {

  •      if (**DEV**) {
    
  •        ReactDOMInstrumentation.debugTool.onCreateMarkupForProperty(propKey, propValue, this._currentElement);
    

This line is the main one that concerns me. It seems like this call should
be inside createMarkupForProperty such that it gets invoked whenever
anyone calls it will get the onCreateMarkupForProperty event. However, we
should not be passing the element to createMarkupForProperty.

Thus, why this PR is difficult, thus my comments in #6062 (comment)
#6062 (comment)
and #6062 (comment)
#6062 (comment)


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
https://github.com/facebook/react/pull/6398/files/295b048adf2a1de62d2572c179da584bccfc7cb1#r58281313

@facebook-github-bot
Copy link

@troydemonbreun updated the pull request.

1 similar comment
@facebook-github-bot
Copy link

@troydemonbreun updated the pull request.

@facebook-github-bot
Copy link

@troydemonbreun updated the pull request.

@troydemonbreun
Copy link
Contributor Author

@jimfb What about this approach? Thanks for your time.

@jimfb
Copy link
Contributor

jimfb commented Apr 5, 2016

@troydemonbreun Yes, this is the approach that I had in mind. However, you're going to want to save the source when a component is rendering (ie. as oppose to onInstantiateReactComponent), because the warning could fire during an update (which won't have a corresponding instantiation). Also, you'll want to give the source location of the jsx element being rendered, rather than the jsx element that lead to the component that has the problem. Maybe something like onMountComponent and onUpdateComponent.

We will need unit tests for all the various cases. Three that come to mind are:

  • A custom/composite component renders 10 div tags, one of which has an unknown property - the source should specify which of the 10 divs is the problem.
  • Unknown property during initial render.
  • No unknown properties during initial render, but yes unknown properties for an update render.

@facebook-github-bot
Copy link

@troydemonbreun updated the pull request.

@troydemonbreun
Copy link
Contributor Author

@jimfb Thanks for the direction! I noticed that ReactDebugTool has those events, is it okay to add those events also to ReactDOMDebugTool, or would you prefer a better way to be DRY about it?

@jimfb
Copy link
Contributor

jimfb commented Apr 8, 2016

@troydemonbreun Probably ReactDOM should register a ReactDebugTool that forwards all the ReactDebugTool events to the ReactDOMDebugTool.

@jimfb
Copy link
Contributor

jimfb commented Apr 13, 2016

Ping @troydemonbreun

@troydemonbreun
Copy link
Contributor Author

troydemonbreun commented Apr 13, 2016

Sorry about the delay, my Dev VM is having problems, looks like I will
need to rebuild. Should get back to it tomorrow.
On Apr 13, 2016 5:51 PM, "Jim" notifications@github.com wrote:

@facebook-github-bot
Copy link

@troydemonbreun updated the pull request.

@troydemonbreun
Copy link
Contributor Author

troydemonbreun commented Apr 15, 2016

@jimfb Trying to grok your last piece of advice. To keep from bothering you, I've spent some time browsing the code trying to infer from current debug tool examples, etc.

Do you mean to create another debug tool and .addDevtool(ReactDebugToolEventForwarderDevTool) in ReactDebugTool? Granted, that doesn't seem to meet the criteria of ReactDOM doing the registering.

I've also thought of .addDevtool(ReactDOMUnknownPropertyDevtool) in ReactDebugTool and extending it to handle the ReactDebugTool events.

Thanks for your time.

@facebook-github-bot
Copy link

@troydemonbreun updated the pull request.

@jimfb
Copy link
Contributor

jimfb commented Apr 15, 2016

Do you mean to create another debug tool and .addDevtool(ReactDebugToolEventForwarderDevTool) in ReactDebugTool?

Yes, I was thinking of a ReactDebugToolEventForwarderDevTool, but no, probably not registered IN ReactDebugTool (see below).

Granted, that doesn't seem to meet the criteria of ReactDOM doing the registering.

I think registration would occur in ReactDefaultInjection (which is ReactDOM specific) or in ReactDOM.js (which would invoke ReactInstrumentation.debugTool.addDevtool();). That way, ReactDOM is doing the registering. I don't pretend to understand the injection stuff, so maybe I'm wrong. cc @sebmarkbage may have better advice there. Also, if you post something and it looks suboptimal, someone will probably be able to jump in with feedback, but obviously it would be better if those people (@sebmarkbage, @spicyj, @syranide, @gaearon) can provide feedback now instead after the code is written.

@facebook-github-bot
Copy link

@troydemonbreun updated the pull request.

@troydemonbreun
Copy link
Contributor Author

troydemonbreun commented Apr 15, 2016

@jimfb onMountComponent appears to be triggered after the unknown property warning is thrown. Is there another method/event in the workflow that might get the specific instance being warned, or did I just code this wrong?

I have pushed my latest work in progress to this PR to show my progress.

Thanks!

);
};

var formatSource = function(source) {
return source ? `(${source.fileName.replace(/^.*[\\\/]/, '')}:${source.lineNumber})` : '';
Copy link
Contributor

Choose a reason for hiding this comment

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

We generally prefer string concatenation instead of template literals.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we have a policy on this; either is fine in my book.

@jimfb
Copy link
Contributor

jimfb commented Apr 15, 2016

The places that those elements get generated is within MountComponent and UpdateComponent, but they're a few calls deeper (I think). My comment about those functions was with regards to your use of instantiateComponent, which was not correct (because of things like updates) Sorry, I wasn't looking at the code and my answer was a little too high-level.

The places that we currently warn are: onCreateMarkupForProperty, onSetValueForProperty, and onDeleteValueForProperty. Each of those properties comes from an element (that element gets created on Mount or Update). We need to know which element those properties came from.

Does that make sense? Let me know if not / if you have questions that I can clarify.

@troydemonbreun
Copy link
Contributor Author

I think that makes sense. I'll dissect internalInstance to get more familiar with that structure.

@facebook-github-bot
Copy link

@troydemonbreun updated the pull request.

@troydemonbreun
Copy link
Contributor Author

@jimfb I've added in more tests for ReactDOMUnknownPropertyDevtool.onCreateMarkupForProperty. How do I trigger the ReactDOMTextareaedge case, in other words, how do I write the test so I know I'm capturing that edge case? I tried some tracing on DOMPropertyOperations.setValueForProperty and rendered a textarea, but I didn't see it make it to that path for the invalid property I set. Thanks!

@jimfb
Copy link
Contributor

jimfb commented May 2, 2016

@troydemonbreun To trigger that case (with the value prop in ReactDOMTextarea), I think you need to update the component:

var container = document.createElement('div');
ReactDOM.render(<textarea value="foo" />, container);
ReactDOM.render(<textarea value="bar" />, container);

ReactDOM will never fire an unknown property warning for that case, so it is probably fine to fix that as a followup PR. (or feel free to fix up this PR).

I'm going to tentatively accept, since I think this PR makes the world incrementally better.

@troydemonbreun
Copy link
Contributor Author

@jimfb Great, thanks for all your help! I'll keep this PR as it is now functionally to keep things simple.

@jimfb jimfb merged commit 7cf61db into facebook:master May 3, 2016
@gaearon
Copy link
Collaborator

gaearon commented May 3, 2016

@troydemonbreun Great job! Sorry that I haven’t been very responsive.

@troydemonbreun
Copy link
Contributor Author

Thanks! You have been responsive and helpful.
On May 3, 2016 6:27 PM, "Dan Abramov" notifications@github.com wrote:

@troydemonbreun https://github.com/troydemonbreun Great job! Sorry that
I haven’t been very responsive.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#6398 (comment)

@troydemonbreun troydemonbreun deleted the r-6062 branch May 4, 2016 14:43
@zpao zpao added this to the 15.y.0 milestone May 16, 2016
@zpao zpao modified the milestones: 15.y.0, 15-next Jun 1, 2016
zpao pushed a commit to zpao/react that referenced this pull request Jun 8, 2016
…warning (facebook#6398)

* New approach for 6062 fix : Show source line number on unknown property warning

* WIP: ReactDebugToolEventForwarderDevTool

* Update event signature to debugID

* Trigger events in ReactDOMComponent

* Renamed to onMountDOMComponent; passing in element directly

* Added debugID; updated simple test

* Added test for multi-div JSX to ref exact line

* Added test for composite component

(cherry picked from commit 7cf61db)
zpao pushed a commit that referenced this pull request Jun 14, 2016
…6398)

* New approach for 6062 fix : Show source line number on unknown property warning

* WIP: ReactDebugToolEventForwarderDevTool

* Update event signature to debugID

* Trigger events in ReactDOMComponent

* Renamed to onMountDOMComponent; passing in element directly

* Added debugID; updated simple test

* Added test for multi-div JSX to ref exact line

* Added test for composite component

(cherry picked from commit 7cf61db)
@zpao zpao modified the milestones: 15-next, 15.2.0 Jun 14, 2016
troydemonbreun referenced this pull request Jul 5, 2016
(cherry picked from commit 74c29b3 and  bc1d59e)
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