MCPcopy
hub / github.com/vercel/next.js / getInlineScriptSource

Method getInlineScriptSource

packages/next/src/pages/_document.tsx:822–866  ·  view source on GitHub ↗
(context: Readonly<HtmlProps>)

Source from the content-addressed store, hash-verified

820 }
821
822 static getInlineScriptSource(context: Readonly<HtmlProps>): string {
823 const { __NEXT_DATA__, largePageDataBytes } = context
824 try {
825 const data = JSON.stringify(__NEXT_DATA__)
826
827 if (largePageDataWarnings.has(__NEXT_DATA__.page)) {
828 return htmlEscapeJsonString(data)
829 }
830
831 const bytes =
832 process.env.NEXT_RUNTIME === 'edge'
833 ? new TextEncoder().encode(data).buffer.byteLength
834 : Buffer.from(data).byteLength
835 const prettyBytes = (
836 require('../lib/pretty-bytes') as typeof import('../lib/pretty-bytes')
837 ).default
838
839 if (largePageDataBytes && bytes > largePageDataBytes) {
840 if (process.env.NODE_ENV === 'production') {
841 largePageDataWarnings.add(__NEXT_DATA__.page)
842 }
843
844 console.warn(
845 `Warning: data for page "${__NEXT_DATA__.page}"${
846 __NEXT_DATA__.page === context.dangerousAsPath
847 ? ''
848 : ` (path "${context.dangerousAsPath}")`
849 } is ${prettyBytes(
850 bytes
851 )} which exceeds the threshold of ${prettyBytes(
852 largePageDataBytes
853 )}, this amount of data can reduce performance.\nSee more info here: https://nextjs.org/docs/messages/large-page-data`
854 )
855 }
856
857 return htmlEscapeJsonString(data)
858 } catch (err) {
859 if (isError(err) && err.message.indexOf('circular structure') !== -1) {
860 throw new Error(
861 `Circular structure in "getInitialProps" result of page "${__NEXT_DATA__.page}". https://nextjs.org/docs/messages/circular-structure`
862 )
863 }
864 throw err
865 }
866 }
867
868 render() {
869 const {

Callers 1

renderMethod · 0.45

Calls 11

htmlEscapeJsonStringFunction · 0.90
prettyBytesFunction · 0.85
encodeMethod · 0.65
requireFunction · 0.50
isErrorFunction · 0.50
stringifyMethod · 0.45
hasMethod · 0.45
fromMethod · 0.45
addMethod · 0.45
warnMethod · 0.45
indexOfMethod · 0.45

Tested by

no test coverage detected