-
Notifications
You must be signed in to change notification settings - Fork 26.1k
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
Pass an HOC to renderPage() #2010
Conversation
This would be amazing to merge as it'd make SSR with styled-components and Next.js much nicer! |
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.
I don't see any harm in adding this 👌
Awesome! I'll work up a JSS example.
…On Sat, May 27, 2017 at 4:22 AM Tim Neutkens ***@***.***> wrote:
***@***.**** approved this pull request.
I don't see any harm in adding this 👌
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2010 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADgUyq5FMX5XXBTvlubKB78wOYAO6uP_ks5r-AeTgaJpZM4Nfs5p>
.
|
Is this waiting on me at all? I'm swamped and can't do the docs right now.
…On Tue, Jun 13, 2017 at 11:38 AM, Max Stoiber ***@***.***> wrote:
Can we land this maybe? 😊 @arunoda <https://github.com/arunoda> @rauchg
<https://github.com/rauchg>
Folks have been asking us about the best way to do Next +
styled-components, this would make it so much better!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2010 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADgUyiqenuQqELZdrEKRoy8cw-dfRYceks5sDtc-gaJpZM4Nfs5p>
.
|
@jcheroske no it's us 😉 You did a great job. |
Whew! For once, it's not my fault. Oh, and sorry about the |
@arunoda lets merge this if you agree 👌 |
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.
very nice to have feature
@arunoda @timneutkens can we make it to be merged and released? it makes cssinjs's ssr so much easier |
@jcheroske @mxstbr @kof @timneutkens just fyi https://twitter.com/arunoda/status/885645093436141568
|
👌 thanks @iamstarkov I saw the tweet 😄 |
.gitignore
Outdated
@@ -13,3 +13,4 @@ npm-debug.log | |||
coverage | |||
|
|||
.DS_Store | |||
.idea |
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.
@jcheroske this is unrelated, sometimes PRs are not merged because of things like this.
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.
I've removed it ❤️
@jcheroske can you please remove .gitgnore change and add a test? Otherwise it seems to be fine. |
No problem.
…On Sun, Jul 23, 2017 at 4:47 AM Oleg Slobodskoi ***@***.***> wrote:
@jcheroske <https://github.com/jcheroske> can you please remove .gitgnore
change and add a test? Otherwise it seems to be fine.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2010 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADgUyilxxgc2vCPjrou58hsR3OD6rfRoks5sQzLigaJpZM4Nfs5p>
.
|
next 3 is released, so i hope we can expect this to be merged soon =) |
Totally. My git skills are not very strong. I was hesitant to make that
change. Thanks for taking care of it.
…On Wed, Aug 9, 2017 at 8:43 AM Tim Neutkens ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In .gitignore
<#2010 (comment)>:
> @@ -13,3 +13,4 @@ npm-debug.log
coverage
.DS_Store
+.idea
I've removed it ❤️
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2010 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADgUysDPF5TNSfMOS-SCv8byfXyQbhfZks5sWdOSgaJpZM4Nfs5p>
.
|
@arunoda this is ready to be merged, I guess tests should be added for it though 🤔 |
Can we merge this? 😊 It's been a while and it would make styled-components + Next soooo much better! |
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.
+1 👌
@mxstbr done 👍, will be included in the Next release. |
AWESOME thank you! I'll send a PR to update the official example and we'll get our docs in sync. |
Hmm, I'm trying to update the example locally but I'm getting "The default export is not a React Component in page: "/"" This is the export default class MyDocument extends Document {
static getInitialProps ({ renderPage, req }) {
const isServer = !!req;
if (isServer) {
const sheet = new ServerStyleSheet()
// I don't know why I have to .bind here, but otherwise this is undefined in sheet.collectStyles
const page = renderPage(sheet.collectStyles.bind(sheet))
const styleTags = sheet.getStyleTags()
return { ...page, styleTags }
}
}
render () {
return (
<html>
<Head>
<title>Next with styled-components</title>
{this.props.styleTags}
</Head>
<body>
<Main />
<NextScript />
</body>
</html>
)
}
} Any ideas why the component could not be a function? |
I tried only importing the static getInitialProps ({ renderPage, req }) {
const isServer = !!req;
if (isServer) {
const ServerStyleSheet = eval("require('styled-components').ServerStyleSheet")
const sheet = new ServerStyleSheet()
const page = renderPage(sheet.collectStyles.bind(sheet))
const styleTags = sheet.getStyleTags()
return { ...page, styleTags }
}
return {};
} |
Based on vercel#2010 this updates the styled-components to use the new renderPage() signature. Note that this doesn't work yet, it throws an error.
Moving discussion to: #2831 |
yay 🎉 |
Awesome! |
This is awesome. @jcheroske I'm gonna do a release now. |
Check |
I would be happy to do that.
…On Wed, Aug 30, 2017 at 3:35 AM Arunoda Susiripala ***@***.***> wrote:
Check ***@***.***
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2010 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADgUyqRgPn_mRH0qI1TllfMKjbeBcZOUks5sdTrogaJpZM4Nfs5p>
.
|
As i can see, renderPage enhancer runs only on the server side, so if it will wrap the page with any tag then there will be a react tree mismatch after browser rendering with unpredictable behavior and some warning from react like "expected server HTML to contain a matching ...", isn't it? |
This feature (wrapping the App) was introduced to support css-in-js libraries like styled-components. You shouldn't use it to wrap extra layout, that's what |
Tricky code. It is worth to mention that actually the App is wrapping this enhancer, and the enhancer is wrapping the Page, but only during server side rendering. JSS example for material-ui still offers to wrap every page manually to handle the styles. It is based on passing pageContext from the App down to the enhancer and then to the Document. |
Sorry, I never did get around to writing docs for this. I'm no longer using next.js, or doing client-side work atm. I hope the project is still healthy. |
I don't use next.js yet either, thats the problem, waiting for someone who uses both. |
There has been some discussion at #1751 and #1776 about changing the
renderPage()
signature to better support SSR and allow wrapping of all pages in the application. My suggestion is to simply allow an HOC to be passed intorenderPage()
.