Skip to content

patdx/preact-react-router-ssr-esm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

preact-react-router-ssr-esm

This is an example of using Preact SSR with React Router and Suspense.

This did not work automatically, I believe the issue is there are two different useContext functions:

  • node_modules/preact/hooks/dist/hooks.js
  • node_modules/preact/hooks/dist/hooks.mjs

Because this is a Node ESM project, the hooks.mjs file is the one that connects to the actual version of Preact that is in use. The hooks.js file connects to an inactive CJS version of Preact.

I patched the react-router and react-router-dom libraries to provide ESM versions using the package exports option. Then, react-router properly uses the useContext function from hooks.mjs.

Test it out by running node server.js, you should see the result:

Load home
<div>Home</div>