Replies: 18 comments 2 replies
-
Feeding the right value into |
Beta Was this translation helpful? Give feedback.
-
@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 😄 |
Beta Was this translation helpful? Give feedback.
-
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
|
Beta Was this translation helpful? Give feedback.
-
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} />
</>
)
} |
Beta Was this translation helpful? Give feedback.
-
I think passing a |
Beta Was this translation helpful? Give feedback.
-
Various linting tools assume that only functions that start with |
Beta Was this translation helpful? Give feedback.
-
A bunch of use-cases to add to @kachkaev's note:
We want these things to be fetched in the component's |
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
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: {...}
}
} |
Beta Was this translation helpful? Give feedback.
-
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) => { /* ... */ }
} |
Beta Was this translation helpful? Give feedback.
-
@devknoll you have typo in first code example in |
Beta Was this translation helpful? Give feedback.
-
@RStankov Based on this reply on the |
Beta Was this translation helpful? Give feedback.
-
@resir014 Haven't thought about that. Makes sense. It makes total sense for Is there a case where you would want to load |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Any update on this proposal or is this now stale? |
Beta Was this translation helpful? Give feedback.
-
Has it been decided whether this will be the approach with the server streaming implementation? |
Beta Was this translation helpful? Give feedback.
-
Hi, |
Beta Was this translation helpful? Give feedback.
-
Goals
<head>
and<body>
Background
The
next/head
pattern 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,
ComponentA
andComponentB
can 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 ahead
component:<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
head
component 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 thehead
component), rather than a side-effect, your websites can take advantage of new Next.js and React features to improve your user's experience.Beta Was this translation helpful? Give feedback.
All reactions