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

Implement proper preact-ssr #767

Closed
wants to merge 15 commits into from
Closed

Conversation

arunoda
Copy link
Contributor

@arunoda arunoda commented Jan 14, 2017

EDIT: Updated inferno example as well

In the current version of preact, it only works(barely) in the client side. But in the server, it still using react.

So, this fixes that issue and improve the use of preact.

Here we've introduce a module alias system where it alias correctly in different places.(Node, webpack, babel)

Preact also doesn't work well with react-hot-loader. And we don't really need preact in the dev mode. So with this, we only run preact only in production.

How to add preact as mentioned above?

Now it's pretty easy. Just create a config in next.config.js like this:

module.exports = {
  alias: function ({ dev, env }) {
    // For the development version, we'll use React.
    // Because, it support react hot loading and so on.
    if (dev) return {}

    // We use preact for the production where it gives us better performance.
    return {
      'react': env === 'client' ? 'preact-compat/dist/preact-compat' : 'preact-compat',
      'react-dom': env === 'client' ? 'preact-compat/dist/preact-compat' : 'preact-compat'
    }
  }
}

@arunoda arunoda modified the milestone: 2.1 Jan 27, 2017
@developit
Copy link
Contributor

Hiya @arunoda - I'd love to play around with this and see if I can run into (and thus fix) any issues with SSR. Would you be able to explain how you're testing this out? Am I right in thinking it's just this:

git clone && npm i && cd examples/using-preact && npm i && npm start

@arunoda
Copy link
Contributor Author

arunoda commented Jan 29, 2017

@developit Yep. That's it.
If you did some changes to next.js code, delete node_modules/next inside the example app and do npm i again.

@thangngoc89
Copy link

@arunoda any plan to merge this? It seems like you're working on may PRs at a time

@arunoda
Copy link
Contributor Author

arunoda commented Feb 9, 2017

@thangngoc89 this is marked for 2.1 release.
So, this won't get merged soon.

@timneutkens
Copy link
Member

This can be closed because of the new preact example.

@arunoda arunoda deleted the preact-ssr branch March 18, 2017 10:57
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants