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

Function loadScriptsInSequence

packages/next/src/client/app-bootstrap.ts:18–56  ·  view source on GitHub ↗
(
  scripts: [src: string, props: { [prop: string]: any }][],
  hydrate: () => void
)

Source from the content-addressed store, hash-verified

16}
17
18function loadScriptsInSequence(
19 scripts: [src: string, props: { [prop: string]: any }][],
20 hydrate: () => void
21) {
22 if (!scripts || !scripts.length) {
23 return hydrate()
24 }
25
26 return scripts
27 .reduce((promise, [src, props]) => {
28 return promise.then(() => {
29 return new Promise<void>((resolve, reject) => {
30 const el = document.createElement('script')
31
32 if (props) {
33 setAttributesFromProps(el, props)
34 }
35
36 if (src) {
37 el.src = src
38 el.onload = () => resolve()
39 el.onerror = reject
40 } else if (props) {
41 el.innerHTML = props.children
42 setTimeout(resolve)
43 }
44
45 document.head.appendChild(el)
46 })
47 })
48 }, Promise.resolve())
49 .catch((err: Error) => {
50 console.error(err)
51 // Still try to hydrate even if there's an error.
52 })
53 .then(() => {
54 hydrate()
55 })
56}
57
58export function appBootstrap(hydrate: (assetPrefix: string) => void) {
59 const assetPrefix = getAssetPrefix()

Callers 1

appBootstrapFunction · 0.85

Calls 9

setAttributesFromPropsFunction · 0.90
thenMethod · 0.80
reduceMethod · 0.80
hydrateFunction · 0.70
resolveMethod · 0.65
errorMethod · 0.65
resolveFunction · 0.50
setTimeoutFunction · 0.50
catchMethod · 0.45

Tested by

no test coverage detected