-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
174 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/next/src/server/app-render/server-inserted-html.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Provider for the `useServerInsertedHTML` API to register callbacks to insert | ||
// elements into the HTML stream. | ||
|
||
import React from 'react' | ||
import { ServerInsertedHTMLContext } from '../../shared/lib/server-inserted-html' | ||
|
||
export function createServerInsertedHTML() { | ||
const serverInsertedHTMLCallbacks: (() => React.ReactNode)[] = [] | ||
const addInsertedHtml = (handler: () => React.ReactNode) => { | ||
serverInsertedHTMLCallbacks.push(handler) | ||
} | ||
|
||
return { | ||
ServerInsertedHTMLProvider({ children }: { children: JSX.Element }) { | ||
return ( | ||
<ServerInsertedHTMLContext.Provider value={addInsertedHtml}> | ||
{children} | ||
</ServerInsertedHTMLContext.Provider> | ||
) | ||
}, | ||
renderServerInsertedHTML() { | ||
return serverInsertedHTMLCallbacks.map((callback, index) => ( | ||
<React.Fragment key={'__next_server_inserted__' + index}> | ||
{callback()} | ||
</React.Fragment> | ||
)) | ||
}, | ||
} | ||
} |
Oops, something went wrong.