-
-
Notifications
You must be signed in to change notification settings - Fork 874
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
Dynamic children break the component #854
Comments
Hi!
It will always be a simple string, if you are explicit, like is shown in the readme: |
Hey there 👋 So I think there's a misunderstanding here. The string value we pass in is certainly not always interpreted as a string, which is why I'm saying there is valid markdown text not supported by this package. We have no control over how our simple strings get parsed into JSX under the hood. Here's some evidence I'm telling God's honest truth. 🙂 |
On a side note, I don't think it's adding all that much ambiguity to accept a list of strings, regarding #855 (comment) Due to the way JSX works, I think it would be perfectly acceptable to support mapped children (although I don't know why you would need to map over children, but it seems like something we shan't judge if it's easy enough to permit it.) As long as the array passed in is checked to be sure each item in the array is only a string, I don't see how it could introduce much confusion. |
(edit: sorry, pressed enter too fast, done:)
I strongly doubt the first statement.
Yes, I strongly believe that you do.
Your evidence is: TypeScript says it’s so. My evidence to contradict you:
Can you please wrap your code to throw some error if Can you otherwise make a reproduction? |
That is not the totality of my evidence. See the final two screenshots. Runtime doesn't lie. |
Right, thanks. I also mentioned some other points though. Why would nobody else see this? Why could you not make a reproduction? My next assumption, as nobody else sees this, is that you have an uncommon JSX transform. Or a custom JSX runtime. Are there other things you can do to make the problem occur or disappear? |
Rest assured, I'm desperately trying to identify the root cause, because I find it as bizarre and unbelievable as you do. I'll let you know if and when I identify what's different about my scenario that confuses the transformer and causes it to become an array. There's nothing special about my project, it's just an ordinary Next.js project with all the default babel transforms OOTB. I will also say this is not the first time I've encountered this (intermittent) error, but it's the first time I decided to contribute rather than hack around it or shop around for a different package - which is what I assume is happening for others, hence the silence around the matter. Putting aside the reproduction, (which I am actively attempting to isolate on the side,) I wonder more about the reasoning behind the resistance to the change? Do you believe accepting |
There’s lots of things that can be thought up, such as: bugs need to be squashed, not shoved under the rug. Stuff like that. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Thanks for more info. So you don’t have dynamic children, which is what this issue is about. Your problem seems to be Parcel being broken: #747 (comment). Hiding these comments so we can focus on the OP. |
Alright, I figured it out. It's not an intermittent JSX behavior after all. It's due to my package react-shadow-scope emulating DSD with So I admit it, it's an upstream issue, not a problem with JSX or this package. 🙂 (Though I still think it's a harmless addition that may avoid such weirdness in the future, but that's your discretion) |
Thanks but no thanks! |
Initial checklist
Affected packages and versions
react-markdown
Link to runnable example
No response
Steps to reproduce
Occasionally, through some whimsical magic, React will choose to render a single string passed to
children
as an array containing one string. I can't seem to reproduce this scenario reliably, it just happens at what seems like random times.This being the case, however, means that there are valid markdown strings being passed as children which this component is not resilient enough to handle. I keep getting variations of the error message:
Where "test" was simply my text string passed as the sole child to the Markdown component. Upon inspection, I was able to discover that my
string
was being converted tostring[]
and then rejected by the package. Not a great experience because there's quite literally nothing that can be done within my control when facing this situation.I was able to fix the problem by temporarily modifying this library's code in my node_modules, from this:
to this:
Expected behavior
It should handle
string[]
children by confirming that each child is indeed of typestring
and thenArray.join('\n')
them to continue processing the markdown.Actual behavior
For
string[]
arrays, it reports an error and crashes the app.Runtime
No response
Package manager
No response
OS
No response
Build and bundle tools
No response
The text was updated successfully, but these errors were encountered: