Skip to content
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

7+: Can't parse links #747

Closed
4 tasks done
Kureev opened this issue Jun 27, 2023 · 17 comments
Closed
4 tasks done

7+: Can't parse links #747

Kureev opened this issue Jun 27, 2023 · 17 comments
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@Kureev
Copy link

Kureev commented Jun 27, 2023

Initial checklist

Affected packages and versions

7.0.0+

Link to runnable example

No response

Steps to reproduce

  • Install react-markdown of version 7 or later.

  • Use following code to reproduce the error

import ReactMarkdown from 'react-markdown'

function App() {
  return (
    <ReactMarkdown>This is a [test](https://google.com)</ReactMarkdown>
  )
}

const root = createRoot(document.getElementById("root"))
root.render(<App />)

Expected behavior

Should render a link like in 6.x

Actual behavior

Cannot convert undefined or null to object

Runtime

Node v16

Package manager

yarn 1

OS

macOS

Build and bundle tools

Parcel

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Jun 27, 2023
@wooorm
Copy link
Member

wooorm commented Jun 27, 2023

Hey! See the syntax highlighting above: you’re doing it wrong.

You should pass a string, not react children.

Check that markdown in the demo: it works fine: https://remarkjs.github.io/react-markdown/.

Also: how do you get that error? Please provide more info on that error.

@wooorm wooorm closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2023
@github-actions

This comment has been minimized.

@wooorm wooorm added the 🙋 no/question This does not need any changes label Jun 27, 2023
@github-actions
Copy link

Hi! Thanks for reaching out! Because we treat issues as our backlog, we close issues that are questions since they don’t represent a task to be completed.

See our support docs for how and where to ask questions.

Thanks,
— bb

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Jun 27, 2023
@Kureev
Copy link
Author

Kureev commented Jun 27, 2023

Hi @wooorm,

Thanks for such a swift response. Not sure if I understand the difference between using a string vs using children (in my case I can ensure it is a string), but even if I do it according to the link you mentioned e.g.

<ReactMarkdown>{`* Follows [CommonMark](https://commonmark.org)`}</ReactMarkdown>

it throws the same error:

ast-to-react.js:392 Uncaught TypeError: Cannot convert undefined or null to object
    at hasOwnProperty (<anonymous>)
    at addProperty (ast-to-react.js:392:11)
    at toReact (ast-to-react.js:188:9)
    at childrenToReact (ast-to-react.js:133:21)
    at toReact (ast-to-react.js:197:20)
    at childrenToReact (ast-to-react.js:133:21)
    at toReact (ast-to-react.js:197:20)
    at childrenToReact (ast-to-react.js:133:21)
    at ReactMarkdown (react-markdown.js:116:19)
    at renderWithHooks (react-dom.development.js:16305:18)
    at mountIndeterminateComponent (react-dom.development.js:20074:13)
    at beginWork (react-dom.development.js:21587:16)
    at HTMLUnknownElement.callCallback (react-dom.development.js:4164:14)
    at HTMLUnknownElement.sentryWrapped (helpers.ts:98:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:16)
    at invokeGuardedCallback (react-dom.development.js:4277:31)
    at beginWork$1 (react-dom.development.js:27451:7)
    at performUnitOfWork (react-dom.development.js:26557:12)
    at workLoopSync (react-dom.development.js:26466:5)
    at renderRootSync (react-dom.development.js:26434:7)
    at performConcurrentWorkOnRoot (react-dom.development.js:25738:74)
    at workLoop (scheduler.development.js:266:34)
    at flushWork (scheduler.development.js:239:14)
    at MessagePort.performWorkUntilDeadline (scheduler.development.js:533:21)

@wooorm
Copy link
Member

wooorm commented Jun 27, 2023

Are you sure your example is everything? Sounds like you are using plugins?

Our tests work fine.
The playground works fine (see previous). It should work.

@wooorm
Copy link
Member

wooorm commented Jun 27, 2023

If you’re migrating and updating, perhaps nuke your package locks and install again?

@Kureev
Copy link
Author

Kureev commented Jun 27, 2023

Are you sure your example is everything? Sounds like you are using plugins?

Nope, why?

If you’re migrating and updating, perhaps nuke your package locks and install again?

Did rm -rf .parcel-cache node_modules yarn.lock, no luck. 6.x works fine 🤷‍♂️ . I mean there are no specific use-cases for me to use 7.x+, so I guess I might just revert to 6.x and live my life happily.

I do suspect it might be related to parcel or something. If I look deeper into the stack trace, I've got somewhat like this:
image

It seems hastToReact gives 0 and info.property is "href". This is the place where it falls apart for me.
Not sure if that's relevant, but I think I'll stop investigating deeper at this step and revert to 6.x, not a biggie

@Kureev
Copy link
Author

Kureev commented Jun 27, 2023

Okay, I couldn't resist and actually figured something out: it does work with parcel's prod build, but doesn't in parcel's dev build (no additional configuration is given for parcel)

@ChristianMurphy
Copy link
Member

Are you sure your example is everything? Sounds like you are using plugins?

Nope, why?

Plugins could be injecting invalid content, or modifying links.

I do suspect it might be related to parcel or something.

That is very possible.
Build tools can over-optimistically optimize/change code and break things.
Usually with some configuration they will work again.

If I look deeper into the stack trace, I've got somewhat like this:

Without being able to replicate the issue, it's difficult to offer many meaningful suggestions.
Consider sharing a sandbox with a replication of the issue https://codesandbox.io/s/

@wooorm
Copy link
Member

wooorm commented Jun 27, 2023

hastToReact exists and we don’t do anything with that. It’s an object from https://github.com/wooorm/property-information/blob/main/lib/hast-to-react.js.
Looks like parcel, or the minifier it uses, is messing it up

@Kureev
Copy link
Author

Kureev commented Jun 27, 2023

Yeah, it seems like it drops the reference to hastToReact for whatever reason. Tried to modify code directly in node_modules and it seems if I retain the ref to hastToReact by logging it, everything works:

if (info.space && info.property) {
  console.log(hastToReact)
  props[
    own.call(hastToReact, info.property)
      ? hastToReact[info.property]
      : info.property
  ] = result
} else if (info.attribute) {
  props[info.attribute] = result
}

So, that said, it seems everything is correct with the library 😸 . Sorry for the false alarm, I'll follow up in Parcel discussions: parcel-bundler/parcel#9113.

Many thanks for your time!

@charIeszhao
Copy link

charIeszhao commented Aug 11, 2023

Came across the exact same issue and we are also using parcel... Thanks for this ticket

Update:
Here's a workaround. Manually install property-information in your project, and import it where you import react-markdown. E.g.

import Markdown from 'react-markdown';
import 'information-property';

// then in tsx, it's working...
<Markdown>{content}</Markdown>

@gao-sun
Copy link

gao-sun commented Aug 11, 2023

Came across the exact same issue and we are also using parcel... Thanks for this ticket

Update: Here's a workaround. Manually install property-information in your project, and import it where you import react-markdown. E.g.

import Markdown from 'react-markdown';
import from 'information-property';

// then in tsx, it's working...
<Markdown>{content}</Markdown>

Context: parcel@2.9.3, react-markdown@8.0.0

memalloc added a commit to memalloc/dkat4 that referenced this issue Nov 4, 2023
when bundling the app using parcel (vite storybook works fine using 8.0.7)

see: remarkjs/react-markdown#747
and  parcel-bundler/parcel#9113
@gmpetrov
Copy link

Came across the exact same issue and we are also using parcel... Thanks for this ticket

Update: Here's a workaround. Manually install property-information in your project, and import it where you import react-markdown. E.g.

import Markdown from 'react-markdown';
import 'information-property';

// then in tsx, it's working...
<Markdown>{content}</Markdown>

Thx!
Btw it's

import 'property-information'
// not import from 'information-property';

@JuliaMerz
Copy link

The error manifested for me as unable to read href of undefined and this solution worked as well. Crazy workaround.

@AdamHG2411
Copy link

Same error message as Julia when using react-markdown v9.0.1 with remark-gfm v4.0.0 and trying to parse a URL or footnote. Importing property-information seems to have fixed it.

@wooorm
Copy link
Member

wooorm commented Feb 7, 2024

Locking as there is no issue here.

@remarkjs remarkjs locked as off-topic and limited conversation to collaborators Feb 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

8 participants