syntax-tree/hast-to-hyperscript

`node._owner` is too unstable

kthjm opened this issue · 9 comments

kthjm commented

#4 is insufficient. node._owner is not always null.

ReactElement.js#L259

return ReactElement(
    type,
    key,
    ref,
    self,
    source,
    ReactCurrentOwner.current, // ← become _owner directry
    props,
  );

ReactCurrentOwner.js

var ReactCurrentOwner = {
  /**
   * @internal
   * @type {ReactComponent}
   */
  current: (null: null | ReactInstance | Fiber),
};

node._owner is so unstable that it is new ReactCompositeComponentWrapper at my local. so can't use it for detect.

React own detect its element by isValidElement function use Symbol, But i don't know whether hast-to-hyperscript relate it better.

sorry for the confusion. my did was superficial.

Can’t you check for '_owner' in node?

kthjm commented

yes. can't check it as null.

or "check" mean "remove"? so, do i create PR just remove node._owner === null ?

No, I mean replace node_owner === null with '_owner' in node.

kthjm commented

r became true ok.

Last question:

Why would this ever fill _owner?

var node = h && h('div');
return Boolean(node && node._owner === null && node.key === null);

What is a ReactCompositeComponentWrapper and why is it set?

kthjm commented

i examined but couldn't clarify the situation.

  • run same process in just node.js, _owner is null in both enviroment.
  • above image code bundled in 'production', and run in browser, _owner is null.

above image situation is run by webpack-dev-server with webpack.HotModuleReplacementPlugin in browser, So the cause may exist in HMR i think.

But sorry, im not sure and i have no idea.

kthjm commented

facebook/react#8295 (comment)

Please don't rely on _owner, it's an implementation detail and might change behavior in future releases. Generally anything with underscores that isn't documented in public API docs isn't a public API ;-)

It’s been there for more than a year. While true, we could also add other checks when React changes, IMHO. I’d say just go for '_owner' in node now!

kthjm commented

ok.
thanks and sorry for a fuss. I am glad to be able to use hast comfortably.
or do i PR? no need?