Next.js: Support for pluggable renderers

Created on 17 Oct 2016  路  11Comments  路  Source: vercel/next.js

Like inferno or preact.

From the end user perspective, it would work as follows.
Configure package.json:

{
  "dependencies:" {
    "next": "x.y.z",
    "next-preact": "x.y.z",
    "preact": "x.y.z"
  }
}

Then we transform JSX to the pragma that, in this example, next-preact would need.
The rendering pipeline would similarly be pluggable.

Most helpful comment

Willing to help on this, any pointers for where to start?

All 11 comments

Willing to help on this, any pointers for where to start?

I'm also totally down to getting Inferno fully working with Next as this project is beyond awesome in my opinion. Great work guys :)

I started trying to see what this would take to implement. I thought this was going to do it, but not seeing any changes.
https://github.com/rektide/next.js/tree/preact-compat

Update: now getting some test failure:

Error: ./dist/client/head-manager.js
Module not found: Error: Cannot resolve module 'preact-compat/lib/HTMLDOMPropertyConfig' in /home/rektide/src/next.js/dist/client
resolve module preact-compat/lib/HTMLDOMPropertyConfig in /home/rektide/src/next.js/dist/client
  looking for modules in /home/rektide/src/next.js/node_modules
    resolve 'file' or 'directory' lib/HTMLDOMPropertyConfig in /home/rektide/src/next.js/node_modules/preact-compat
      resolve file
        /home/rektide/src/next.js/node_modules/preact-compat/lib/HTMLDOMPropertyConfig doesn't exist
        /home/rektide/src/next.js/node_modules/preact-compat/lib/HTMLDOMPropertyConfig.webpack.js doesn't exist
        /home/rektide/src/next.js/node_modules/preact-compat/lib/HTMLDOMPropertyConfig.web.js doesn't exist
        /home/rektide/src/next.js/node_modules/preact-compat/lib/HTMLDOMPropertyConfig.js doesn't exist
        /home/rektide/src/next.js/node_modules/preact-compat/lib/HTMLDOMPropertyConfig.json doesn't exist
      resolve directory
        /home/rektide/src/next.js/node_modules/preact-compat/lib/HTMLDOMPropertyConfig doesn't exist (directory default file)
        /home/rektide/src/next.js/node_modules/preact-compat/lib/HTMLDOMPropertyConfig/package.json doesn't exist (directory description file)
[/home/rektide/src/next.js/node_modules/preact-compat/lib/HTMLDOMPropertyConfig]
[/home/rektide/src/next.js/node_modules/preact-compat/lib/HTMLDOMPropertyConfig.webpack.js]
[/home/rektide/src/next.js/node_modules/preact-compat/lib/HTMLDOMPropertyConfig.web.js]
[/home/rektide/src/next.js/node_modules/preact-compat/lib/HTMLDOMPropertyConfig.js]
[/home/rektide/src/next.js/node_modules/preact-compat/lib/HTMLDOMPropertyConfig.json]

HTMLDOMPropertyConfig does not appear in the Preact or preact-compat codebase. It's use in Next.js is exclusively in head-manager. I tried commenting out the import and it's use as so but got 3 other test errors that were a bit harder to decipher: const attr = /*HTMLDOMPropertyConfig.DOMAttributeNames[p] ||*/ p.toLowerCase(). I still haven't really started figuring out what it's asking for or what React is providing here.

Very impressive @rektide ! Looking forward to seeing this evolve. Ideally we get it down to 2 imports (next-preact and preact peer dep) and 1 tweak on the config :)

Piggybacking off @rektide's work, I was able to get it working by...

git clone https://github.com/zeit/next.js next
cd next
npm install
npm install -i preact-compat/react preact-compat/react-dom preact preact-compat
# comment out HTMLDOMPropertyConfig
npm build # this will fail on the tests, but will still give you a dist/client
# copy that dist/client to whatever app you've got next running on

Some additional work needs to be done to figure out how to make HMR play nice with non-react things. react-hot-loader does some crazy stuff. @developit has minimalist way to make HMR work more universally: https://github.com/developit/preact/issues/168#issuecomment-222390093

I think the big things needed from next are:

  1. remove the dependency on HTMLDOMPropertyConfig, it can just be a map copied into next or a separate module.
  2. replace react-hot-loader with something that just adheres to the HMR API.

@matthewmueller Tests pass for me!

That's really amazing (and simple) @matthewmueller

Both inferno & preact lack a HTMLDOMPropertyConfig component, but I'm not sure that they should need to offer one...

Paging @nkzawa and @arunoda. I think we should think about even documenting in the Wiki what the API surface that we depend on from React is. This will allow people to keep experimenting with engine improvement and minimization :)

This is already possible with simple webpack overrides.

Was this page helpful?
0 / 5 - 0 ratings