f5a89eb00a
We have existing rule for pages ssr that `next/dist/server` and `next/dist/shared` will not be bundled, but we shouldn't apply it to rsc layers since the they should bundle the dependencies in their own way. Adding a test that using `next/head` in the page, since head is exported from `next/dist/shared`, expect the page is not broken but we don't expect it's working ## Bug - [ ] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md`
22 lines
806 B
TypeScript
22 lines
806 B
TypeScript
'use client'
|
|
|
|
import React, { useContext } from 'react'
|
|
|
|
export type ServerInsertedHTMLHook = (callbacks: () => React.ReactNode) => void
|
|
|
|
// Use `React.createContext` to avoid errors from the RSC checks because
|
|
// it can't be imported directly in Server Components:
|
|
//
|
|
// import { createContext } from 'react'
|
|
//
|
|
// More info: https://github.com/vercel/next.js/pull/40686
|
|
export const ServerInsertedHTMLContext =
|
|
React.createContext<ServerInsertedHTMLHook | null>(null as any)
|
|
|
|
export function useServerInsertedHTML(callback: () => React.ReactNode): void {
|
|
const addInsertedServerHTMLCallback = useContext(ServerInsertedHTMLContext)
|
|
// Should have no effects on client where there's no flush effects provider
|
|
if (addInsertedServerHTMLCallback) {
|
|
addInsertedServerHTMLCallback(callback)
|
|
}
|
|
}
|