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.

Compatiblity of PreactX alpha 0 with Preact.Router

See original GitHub issue

I just tried to migrate my Preact app to Preact X, but it’s crashing when it’s starting. Should it run with the Preact router, or is there any known incompatibility?

util.js:69 Uncaught TypeError: Cannot read property 'replace' of undefined
    at segmentize (util.js:69)
    at rank (util.js:77)
    at rankChild (util.js:81)
    at prepareVNodeForRanking (util.js:64)
    at Array.filter (<anonymous>)
    at Router.getMatchingChildren (index.js:213)
    at Router.render (index.js:231)
    at _ (index.js:126)
    at _ (index.js:137)
    at d (children.js:74)

I use Preact together with Parcel.js for module bundling and with the previous version it was running perfectly.

After the migration I just removed the third parameter from the render function

render(<App />, document.body)

Instead of using document.body I also tried to use a div inside of the body as root element, but I got the same error as before. I use preact-router in the latest version 2.6.1 and preact-compat v3.18.4

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
janbaercommented, Mar 9, 2019

I just invested a bit more time now to investigate the problem and I found out, that the problem was in my code in the Router.onChange eventhandler. In the previous version I read e.current.attributes, but it seem that this is no longer working. So instead it’s now e.current.props.

I looked into the last commits of the preact router, and I found where it was changed:

https://github.com/developit/preact-router/commit/ebbda180a8b8db2d42489cfb1d05ba79a74c15ca#diff-34a6d62af0cf0b784f8444529f3130efR65

After I fixed it, Preact X is now running with my project. Thanks to all contributors to provide us all the new features. Especially React.Fragment and also the Hooks I missed very much.

2reactions
Kanayecommented, Mar 6, 2019

Preact X doesn’t use preact-compat anymore instead Preact X ships a compat layer in preact/compat. There is already a WIP PR for updating preact-router developit/preact-router#298

Updating preact-render-to-string shouldn’t be that much of a hassle. I might give it a try later if no one has created a PR for it by then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Preact-router - npm.io
Note: This is not a preact-compatible version of React Router. preact-router is a simple URL wiring and does no orchestration for you.
Read more >
How to use React Router with Preact - Stack Overflow
I'm not sure if it's a compatibility problem, or a configuration problem. I've tried using just one pair of routes ( App and...
Read more >
reznord - npm
preact. Fast 3kb React-compatible Virtual DOM library. marvinhagemeister ... Render JSX to an HTML string, with support for Preact components.
Read more >
React Router v6 Preview
react -router-dom@6.0.0-alpha.2 reveals the total bundle size decreased by 70%. Smaller bundles means your app loads more quickly, especially ...
Read more >
Switching to Preact (from React)
preact/compat is our compatibility layer that allows you to leverage the many libraries of the React ecosystem and use them with Preact.
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