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

Function onStart

packages/next/src/client/index.tsx:654–692  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

652 // This function has a return type to ensure it doesn't start returning a
653 // Promise. It should remain synchronous.
654 function onStart(): boolean {
655 if (
656 !styleSheets ||
657 // We use `style-loader` in development, so we don't need to do anything
658 // unless we're in production:
659 process.env.NODE_ENV !== 'production'
660 ) {
661 return false
662 }
663
664 const currentStyleTags: HTMLStyleElement[] = looseToArray<HTMLStyleElement>(
665 document.querySelectorAll('style[data-n-href]')
666 )
667 const currentHrefs: Set<string | null> = new Set(
668 currentStyleTags.map((tag) => tag.getAttribute('data-n-href'))
669 )
670
671 const noscript: Element | null = document.querySelector(
672 'noscript[data-n-css]'
673 )
674 const nonce: string | null | undefined =
675 noscript?.getAttribute('data-n-css')
676
677 styleSheets.forEach(({ href, text }: { href: string; text: any }) => {
678 if (!currentHrefs.has(href)) {
679 const styleTag = document.createElement('style')
680 styleTag.setAttribute('data-n-href', href)
681 styleTag.setAttribute('media', 'x')
682
683 if (nonce) {
684 styleTag.setAttribute('nonce', nonce)
685 }
686
687 document.head.appendChild(styleTag)
688 styleTag.appendChild(document.createTextNode(text))
689 }
690 })
691 return true
692 }
693
694 function onHeadCommit(): void {
695 if (

Callers 1

doRenderFunction · 0.70

Calls 6

looseToArrayFunction · 0.85
getAttributeMethod · 0.80
mapMethod · 0.45
forEachMethod · 0.45
hasMethod · 0.45
setAttributeMethod · 0.45

Tested by

no test coverage detected