-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
onUpdate and onInitialized shouldn't pass a DOM element #49
Comments
Having thought about this a bit more, I'm not sure why returning a reference to a DOM node is a priori bad. Some clients of this code need to operate on this DOM node, and those who don't can easily grab whatever they want out of it, especially with destructuring assignment e.g. via The editor component can't operate without that entire node, including a large interconnected set of _attributes and _methods, and it's definitely not practical to break out all of these into individual arguments to a callback, so that components like the editor can stitch it all back together on the other end. |
@nicolaskruchten Doesn't it concern you that you literally can't explain to me why you need all of the node? That it's just a huge undocumented kitchen sink of mystery secret sauce that we just have to grin and bear it? It's a big bundle of "magic". But also again, it's a DOM node, it has absolutely no business being passed around as a prop, especially as a glorified container object. And because it's a DOM node instance, everything gets completely tied to that mutated instance that only works during runtime at that particular moment. You can't reproduce any issues that are related to it, because it's all just instances referencing other instances that then get mutated somewhere secret. You can't serialise or unserialise it for testing or saving/loading state, because it's a whole DOM node that only exists during its creation by some other unrelated DOM manipulation code. It's a huge cheat that subverts the normal way props are used in React for unidirectional data flow. I understand that |
I'm happy to explain why, I'm not sure where you get the idea that I literally can't :) When I'm also not sure why you say things can't be reproduced... We do it all the time in development: we can call Regarding serialization, one only needs to serialize Finally, you refer to the use of I hope this helps :) |
Heads-up: #63 will go partway towards alleviating the issues you bring up. The DOM node will still be passed along, but as a second parameter to the callback. In the vast majority of cases, people will be able to ignore that parameter and just use the first one. This is technically a breaking change (even though I'll bet only the editor relies on the _attributes!) and will trigger a major version bump. |
Thanks, this helps to clear things up better. Previously I thought only What I meant about reproducibility, is about being able to isolate an issue for debugging. You have to recreate the graph div via Plotly (and trigger the same changes) up to the moment before the issue happened on every debugging attempt, instead of the usual type of React debugging where you can just toggle between different props/state and re-trigger or step through the issue instantly as various components re-render. When everything's tied to an instance (instead of static prop data), that instance needs to be recreated continuously to be able to debug it. Additionally, the React dev tools will choke ( Hopefully these changes will help to alleviate those debugging issues by making the |
Certainly the documentation around Now I see what you mean by reproducibility, which I would call "path-independence" in this context... Basically the notion that This is certainly the requirement we have with respect to Unfortunately, to set expectations: this PR will do little to change this particular state of affairs. You may still encounter path-dependent bugs like #45 or #53, regardless of whether or not you store the DOM node and its _attributes in a state container. |
Closing as #63 is merged, but I'm happy to keep the thread going if you have more questions. |
Currently, the way the
onUpdate
andonInitialized
callbacks are sending updates back up is by passingthis.el
, a.k.a. thegraphDiv
/gd
.This has created some awkward breakages of the React lifecycle because now instead of passing plain prop objects back up, there's a whole DOM element with hidden extra data smuggled aboard (
_fullData
,_fullLayout
, the element ref itself, possibly more undocumented deps…?) being passed around instead.The updated
data
andlayout
objects should be sent separately, either as individual callback params, or within a plain object wrapper. If the additional values (graphDiv
,_fullData
,_fullLayout
, etc…) are still important dependencies that needs to be passed back up by the callback, then they should be broken out into their own unique params / wrapper keys. Then at least these advanced dependencies can be properly documented.For example,
react-plotly.js-editor
has difficult state management because it's been coded to rely on thegraphDiv
exposed by the callbacks, instead of individual dependencies (data
,layout
,_fullData
,_fullLayout
,_context
).The text was updated successfully, but these errors were encountered: