laggingreflex / preact-markdown

Markdown in Preact Markup

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stops working on preact@10.5.13 and preact-render-to-string@5.1.19

Benjythebee opened this issue · comments

I recently upgraded preact from 8 to 10 and updated preact-markdown from 0.5.0 to 2.0.0.

However, the component
<Markdown markdown={'my content'} markupOpts={{}} markdownOpts={{}} />
returns <undefined markup="..."> when rendering with no console errors.

    "preact": "^10.5.13",
    "preact-markdown": "^2.0.0",
    "preact-render-to-string": "^5.1.19",
    "preact-router": "^3.2.1",

Using preact/debug; I obtain:

Uncaught (in promise) Error: Undefined component passed to createElement()

You likely forgot to export your component or might have mixed up default and named imports<#text markup="<p></p>" trim="false" type="html" />


  in #text
  in Markdown

The example seems to be working.

Could it be a case of multiple preact instances? This library uses preact's h function internally, which only renders when the render function also comes from the same preact instance. For that reason preact is set as a peer-dependency.

If you've upgraded your dependencies versions, it might be worth trying nuking the entire node_modules and reinstalling.

ahah thanks for the option, nuked it and still getting the error...

Also I tried the example;
I noted the package.json imports preact-markdown@1.0.0 which doesn't exists but that's besides the point (I changed it back to 2.0.0.

I made the following html after npm run build:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="main.js"></script>
    <title>Document</title>
</head>
<body>
    
</body>
</html>

which imports the main.js from dist.

Openning the html file on a browser gives an error

Uncaught TypeError: Cannot read property '__k' of null
    at Z (main.js:1)
    at Module.<anonymous> (main.js:1)
    at n (main.js:1)
    at main.js:1
    at main.js:1

I just tried again replicating the example separately (with latest dependency versions) and I wasn't able to reproduce this on my end. So I'm afraid I won't be able to help you much.

If you could create a minimally reproducible example repo I'd be glad to look at it.

https://github.com/Benjythebee/preact-markdown/tree/master/example
I added a .gitignore in master cause the node_modules in example was too big.

I've updated the example. But I'm still not able to reproduce the issue.

For your previous error (Cannot read property '__k' of null) can you try this:

npm run build -- --mode=development --watch

It'll output unminified JS so the error messages will point to the right code location that might help.

Also you said you've started having this problem only when you upgraded (from 1.0.0 to 2), and so you had no problem with v1.0.0? You can try going back via Git history to check if example in previous commit works or not.

Or is it the preact version that's causing issues? You can try reducing/incrementing versions in both independently to do a thorough testing. Do them without the caret ^ to make sure exact versions are installed.

OK, I pulled and the example runs now. It could be a rendering issue when using preact-render-to-string but I'm struggling in re-creating a repro.

Also you said you've started having this problem only when you upgraded (from 1.0.0 to 2), and so you had no problem with v1.0.0? You can try going back via Git history to check if example in previous commit works or not.

No, v1 doesn't exists on npm, so I couldn't npm install it. I upgraded from 0.5.0 to 2.0.0.

I'll work on it during the week to try to find what's up...