-
-
Notifications
You must be signed in to change notification settings - Fork 27k
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
server-side render POC #172
Conversation
@@ -10,7 +10,6 @@ | |||
var path = require('path'); | |||
var autoprefixer = require('autoprefixer'); | |||
var webpack = require('webpack'); | |||
var HtmlWebpackPlugin = require('html-webpack-plugin'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently HTML must be generated on the server.
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks! |
@@ -98,23 +95,6 @@ module.exports = { | |||
return [autoprefixer]; | |||
}, | |||
plugins: [ | |||
new HtmlWebpackPlugin({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The obvious drawback is that HtmlWebpackPlugin
did some HTML postprocessing and most importantly it automatically added chunk hashes to imported files, which now needs to be done manually on the server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can also combine HtmlWebpackPlugin and SSR, it is limiting, e.g. doesn't support streaming (since it's not rendered by react fully), but you can totally get access to generated HTML on the server
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
This looks very cool. We won’t get this in anytime soon because of the complexity, but I could imagine somebody wanting to maintain a fork that allows that. |
Closing because this is not going to be actionable for us—props for doing it though! |
@gaearon weren't you planning to introduce optional features? Couldn't this be something like |
No, we don’t plan to add optional features at this point. |
Then it should be core. Facebook's crawlers do not run JS so you need SSR for your OGP And this is not a Facebook-specific problem. You might not see this since (I assume) you are at the developer side of things and not at the user side, but an app that doesn't support Open Graph, Twitter Cards or other The README states that "[our] environment will have everything [we] need to build a modern React app", but it doesn't. An app that can't be displayed properly on social media is not a modern app. |
I would love for server-side rendering to be easy to set up, extremely simple, and just a core React thing. Unfortunately that is not the case for server-side rendering today. I think the way to get there is not to put a complex implementation into So here is a challenge for folks that would like server-side-rendering to be part of create-react-app. Could you make a new library so that, to make an app with server-side-rendering, all you have to do is:
|
I believe there is some sort of a misunderstanding. Just because CRA gives you a client-side app, doesn’t mean you can’t add something to its output for the server side. You can take the built There is absolutely nothing preventing you from adding |
Added instructions about |
To add to @lacker’s comment, here’s a bunch of non-obvious things you need to solve for good server rendering setup: https://react-server.io/. Yes, such solutions exist, but you can see that even that solution has a very opinionated API. This is because setting up server rendering correctly is a hard problem, and very hard to do in a generic way while maintaining beginner friendliness. |
We already came up with a similar workaround. It worked fine because the only route we had was What we are looking for is a proper isomorphic (universal) solution to this. Sadly, the "solutions" available to the community today feel more like workarounds than actual solutions. If SSR is too complex then let's fix this. We can discuss what is needed to make it simpler and push vendors to improve the situation. The situation isn't going to improve if we admit defeat and stop challenging the stack. We should challenge it and not just one by one, but as a whole stack so everything fits together perfectly. This project looks like the place to do it since it is official and also defines a stack, unlike React or Webpack which are just parts of stacks. I'm not suggesting we add everything to the project, I'm suggesting we add simple things and try to make the rest simpler. Not everything has to be in the example code. Just support for them have to be there so a developer can easily use them when their time comes. |
The scope of this problem is much bigger than the scope of this project. We don't have a complete team supporting it full time which is what I believe would be necessary for the kind of project you are describing. It would be a noble effort and we'd be happy to link to it, but since we don't actively use React on the server in production, we are not the right people to build this. If your company is willing to invest that effort, I'm sure there will be plenty of interest. |
I know that you don't work on things that you don't need (like Windows support) and I absolutely understand, but is the line you draw really that thick? We trust Facebook and React, but every part of the stack that does not have support from FB is in flux and SSR is one of them. Even FB does it in Hack, it still does SSR and surely has something to offer to JS land. I think even an intent to include SSR in this project would be enough help. You can analyse what makes SSR so complex, open necessary issues and tag them community responsibility. If something is necessary but too complex, we should be asking it to be simplified instead of ignoring it. (Also, after I started following your tweets, I realised that CRA is already helping its dependencies improve. That is great!) |
This is not fair, Create React App supported Windows since its initial release, and we always test it.
So can you 😉 . We are not a giant team, there’s like four people working on React and they have a ton of other work to do that is currently a higher priority for us. We are inspired by the work @aickin and other people are doing to make SSR better in React, and we are keeping these efforts in mind as we work on React future. |
I didn't mean CRA :)
Does that mean you would accept an issue here? I would get zero attention if I do it under my name. I also don't want to do this under other "solutions" (like React Server) because this complexity is the reason they exist. It will basically be saying "Let's fix these so people won't need your project." and you would probably get insulted and blocked for that on GitHub 😄 |
One more POC: https://github.com/kirill-konshin/create-react-server to @lacker |
…piler so that you can import images and other files (references facebook#172)
This is just a throwaway code not meant to be ever merged
This PR is just a proof of concept how server side render could be implemented. I am aware that it's quite opinionated and introduces new dependency on
express
.I am open to any discussion how much sane this would (or would not) be, I'll gladly re-implement it in production quality if we decided to go this way.