Closed medfreeman closed 7 years ago
Hi @medfreeman, thanks for the thorough details!
Am I correct in assuming this is an issue with hast-to-hyperscript
? I think we need to change code in there.
For a solution, I’m thinking hast-to-hyperscript
should not coerce to strings if dealing with a React tree. Do you know if React’s VDOM accepts non-strings in normal elements too, or just for components?
@wooorm Thanks for your really quick answer !
I wasn't sure if it was an abnormal behavior in hast-to-hyperscript or remark-react, since i don't understand all the finer points, but that makes sense.
About react vdom, i'm looking into this right now.
About React's VDOM and non-strings in normal html elements, i'm not sure of the exact answer, but i'm getting a pretty good idea of how the thing works after a few hours of reading doc / looking at react's code. However i'm just too tired to express this properly, i'll make you a nice bullet list with code references tomorrow.
Please go to sleep! 💤 This can wait!
Do you know if React’s VDOM accepts non-strings in normal elements too, or just for components?
The answer is basically yes, but the processing differs depending on the node / attribute:
style
, dangerouslySetInnerHTML
, children
, __html
, suppressContentEditableWarning
are processed separately, i won't go into the details, info here (code ref)setValueForAttribute
, is stringified ('' + value)
or removed if value is nulldata-
or aria-
attribute, it goes through setValueForProperty
where:
mutationMethod
, for now that only applies to the value
property and has a value, it is stringified, with exceptions for number validation in input type fields (for browser validation/focus/blur reasons)MUST_USE_PROPERTY
flag (ref. here), it is passed as is to the corresponding dom object propertyReferences in order:
Differences with html attributes
setValueForProperty
and setValueForAttribute
reference
propertyInfo
config definition
facebook/react#140 facebook/react#7311
I don't know if everything will be of use to you, but i hope i've been concise enough !
This is really awesome! I’m working on better props tests, and support for this, but that may take a while depending on how it goes (I’ve got a busy week unfortunately)!
Thanks ! Can you explain what part of this hast-to-hyperscript has to support ? Everything ? Just verifying variable types ? In theory couldn't just everything pass through ? Sorry but i don't exactly understand the ins and outs of hyperscript, and if there is sanitizing work to do. If you can make a resume, i can try to make a PR.
So the current tests were focussed on creating the same tree through hast-to-hyperscript
and the original h
(in this case React.createElement
).
However, I found that to be a bit buggy when I was rewriting the tests: now I’m going:
hast -> hast-to-hyperscript(React.createElement) -> renderToStaticMarkup -> rehype-parse
hast -> rehype-stringify -> rehype-parse
...and comparing the two trees for deep equality. I found some bugs and am working on fixing them!ok i understand ! thanks for your work !! i'll use coercition in the mean time ! do not hesitate to ask if you need a bit of help, i can certainly spare a few hours during the next days.
I’ve pushed a new version to hast-to-hyperscript
, 3.0.0, haven’t had time to update this though!
Should i just make a PR updating hast-to-hyperscript
?
Yeah!
Hi, thanks for your work !!
here's a bit of context.
I'm developing a common mark generic extensions plugin, supporting this kind of syntax:
!Element[content](argument){ properties }
I'm using
!Icon[My-tooltip](my-icon){ floating }
for testingMy remark inline tokenizer returns this node:
Notice the boolean property named
floating
.I can properly have my corresponding react component
TooltipIcon
render with the following snippet (es6):Whereas my
floating
property is effectively boolean inside the HAST tree generated by remark, it is stringified by hast-to-hyperscript at this line, called here in remark-react.In order to avoid a react
PropTypes
type warning, i'm actually forced to also allowString
in addition toBoolean
propTypes for thefloating
property inside my component. I then coerce thefloating
property back to boolean, in order for the subcomponent (which requiresfloating
to be boolean) to be happy.Here's my TooltipIcon component:
I hope you get the general idea, and if you can tell if it's a requirement to have every property stringified. Because in this case only
String
properties can be passed to React if i'm not mistaken.