Repository navigation
Replies: 18 comments 2 replies
|
Feeding the right value into |
|
@kachkaev I think that's a legitimate concern. One idea was to allow only This would work for e.g. Google which will use the Curious if you think that would be sufficient or if you have other thoughts/ideas 😄 |
Well whenever we query anthing on server with graphql there are two possibilities, there is an error or there is no error. The solution you are looking is simply solvable by useEffect hook Also it covers for almost every case with single mo |
Maybe this could be made a bit more ergonomical by also allowing an export Edit: 🤔 Or rather, I guess the complementary would be a component that wraps the rendering of the page's head. // _page.js
export function Head({ Component, pageProps }) {
return (
<>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Component {...pageProps} />
</>
)
} |
|
I think passing a |
|
Various linting tools assume that only functions that start with |
|
A bunch of use-cases to add to @kachkaev's note:
We want these things to be fetched in the component's |
|
@emirotin The function MyPage() {
// ...
}
MyPage.getInitialProps = async () => {
const metadata = await fetchFromPrismic(/* ... */)
return { metadata }
}
export default MyPage
export function Head({ metadata }) {
return <>{convertToTags(metadata)}</>
}This will work both on initial SSR and CSR. |
|
Considering #9160, would it make sense to return HTML attributes from the new GS(S)P methods? E.g. // Or getServerSideProps
export function getStaticProps({ params }) {
return {
htmlAttributes: {
lang: params.lang
},
props: {...}
}
} |
|
Why is separate export needed? Can the head function be attached to the default export similar to how function MyPage() {
// ...
}
MyPage.getInitialProps = () => {
// ...
}
MyPage.getHead = (/* props returned from getInitialProps */ ) => {
// ..
}Couple of benefits of this approach:
I have something export default createPage() {
query: GRAPHQL_QUERY,
// ...
head: (dataFromQuery) => { /* ... * /}
component: (dataFromQuery) => { /* ... */ }
} |
|
@devknoll you have typo in first code example in |
@RStankov Based on this reply on the |
|
@resir014 Haven't thought about that. Makes sense. It makes total sense for Is there a case where you would want to load |
|
I wrote another RFC that gets into how to send I'm glad you are all interested in solving this problem. There are many assumptions in Next.js architecture that makes this a difficult problem to solve. |
|
How would this work with styled-components? It needs to render he whole tree to be able to collect the styles which it then writes to the head. |
|
Any update on this proposal or is this now stale? |
|
Has it been decided whether this will be the approach with the server streaming implementation? |
|
Hi, |
Uh oh!
There was an error while loading. Please reload this page.
Goals
<head>and<body>Background
The
next/headpattern makes it very easy for your components to configure the rendered<head>, but it has some major drawbacks:HTML is blocked until after the entire React tree is rendered
Since
<Head>can appear anywhere in your component tree and in turn modify the<head>tag, Next.js must render your entire tree before it can start sending any HTML to the client.This leads to a chunk of dead time where the browser does nothing other than wait for the server, when it could have otherwise been loading and processing resources like CSS or JavaScript.
Non-deterministic in Concurrent Mode
<Head>depends on the side-effects of rendering happening in a specific order:In Concurrent Mode,
ComponentAandComponentBcan be mounted in any order, leading to a non-deterministic value for<title>.Proposal
Next.js should allow you to define a
<head>once per page by exporting aheadcomponent:<Head>should continue to work, but Next.js should warn in development mode that you are missing out on some features and that it may be removed in a future version.An exported
headcomponent should receive the same props as the page component, so you can support e.g. dynamic titles withgetInitialProps:You can use components to continue sharing and composing pieces of your
<head>:With the exception of
<title>, most pages already tend to render the same<head>. By making this explicit (via theheadcomponent), rather than a side-effect, your websites can take advantage of new Next.js and React features to improve your user's experience.All reactions