question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: working with render props

See original GitHub issue

Isn’t possible to reproduce render props component like that:

import { Foo } from './Foo'

# Hello Foo

<Foo>
  {() => {
    const bar = 'bar'

    return (
      <Bar bar={bar} />
    )
  }}
</Foo>

I noticed that in the MDAST => MDXAST process you just turn HTML into JSX nodes, but in this case the line breaks between const and return is a trade off, because the parse is a Paragraph instead of the same scope of HTML.

So, I was trying to figure out how fix this and I think that what can be a possible solution is create something like a merge between nodes when the HTML node that has the opening tag is invalid (without enclosing tag). I don’t know if this can generate some trade offs or is a solution that fit in all cases. So, I didn’t think yet how this can affect performance, but was the only thing that came in mind in that case 😞

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
timneutkenscommented, Jan 26, 2019

Just to give some context to @erquhart’s comment/question:

For the initial MDX implementation I kept in mind a very strict superset of Javascript (or not even JS, as JSX is not JS), the only thing MDX parses are import export and jsx jsx is handled by unified, we convert the html nodes to jsx nodes for consistency. import/export are parsed in the simplest way possible, if the ast node starts with import/export it’s an import/export, if not it’s normal text.

I’ve always thought that writing render props / other JS in MDX documents doesn’t make sense as it introduces unnecessary complexity and there are other ways to handle it, for example as you can use JSX you could move that code into a component and make that component render everything you need.

It’s also a good idea to keep in mind that soon render props will in most cases be replaced by Hooks.

The only case that is interesting to explore deeper is the possibility to write JSX inside of markdown syntax like **<Something />** which is currently not possible. I know @johno has been playing around with this idea for a while though.

2reactions
timneutkenscommented, May 8, 2018

So the only reason Pedro’s example doesn’t work is the empty line break between const and return, remark Will parse that as 2 paragraph nodes

Read more comments on GitHub >

github_iconTop Results From Across the Web

this.props is duplicating to the next component sometimes bug ...
The error seems to be when I call super(props) as it uses the props from the previous component. When I render it, it's...
Read more >
A Story of a React Re-Rendering Bug - Engineering Blog
We know, by default, one React component will only be re-rendered if its state gets changed, either caused by props change, or triggered...
Read more >
React's Render Props in Practice - Medium
If you are a front-end developer using ReactJS, you've probably caught a lot of buzz about render props and how they are supposed...
Read more >
React re-renders guide: everything, all at once - Developer way
Comprehensive guide on React re-renders. The guide explains what are re-renders, what is necessary and unnecessary re-render, ...
Read more >
How React Uses Closures to Avoid Bugs
props (you shouldn't do that). I'm talking about when the parent component re-renders and passes new props, this.props suddenly points to completely new...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found