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

Function maybeExecuteScript

packages/next/src/client/route-loader.ts:250–272  ·  view source on GitHub ↗
(
    src: TrustedScriptURL | string
  )

Source from the content-addressed store, hash-verified

248 new Map()
249
250 function maybeExecuteScript(
251 src: TrustedScriptURL | string
252 ): Promise<unknown> {
253 // With HMR we might need to "reload" scripts when they are
254 // disposed and readded. Executing scripts twice has no functional
255 // differences
256 if (process.env.NODE_ENV !== 'development') {
257 let prom: Promise<unknown> | undefined = loadedScripts.get(src.toString())
258 if (prom) {
259 return prom
260 }
261
262 // Skip executing script if it's already in the DOM:
263 if (document.querySelector(`script[src^="${src}"]`)) {
264 return Promise.resolve()
265 }
266
267 loadedScripts.set(src.toString(), (prom = appendScript(src)))
268 return prom
269 } else {
270 return appendScript(src)
271 }
272 }
273
274 function fetchStyleSheet(href: string): Promise<RouteStyleSheet> {
275 let prom: Promise<RouteStyleSheet> | undefined = styleSheets.get(href)

Callers

nothing calls this directly

Calls 5

appendScriptFunction · 0.85
getMethod · 0.65
resolveMethod · 0.65
setMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected