MCPcopy
hub / github.com/vuejs/core / ssrRenderTeleport

Function ssrRenderTeleport

packages/server-renderer/src/helpers/ssrRenderTeleport.ts:10–50  ·  view source on GitHub ↗
(
  parentPush: PushFn,
  contentRenderFn: (push: PushFn) => void,
  target: string,
  disabled: boolean,
  parentComponent: ComponentInternalInstance,
)

Source from the content-addressed store, hash-verified

8} from '../render'
9
10export function ssrRenderTeleport(
11 parentPush: PushFn,
12 contentRenderFn: (push: PushFn) => void,
13 target: string,
14 disabled: boolean,
15 parentComponent: ComponentInternalInstance,
16): void {
17 parentPush('<!--teleport start-->')
18
19 const context = parentComponent.appContext.provides[
20 ssrContextKey as any
21 ] as SSRContext
22 const teleportBuffers =
23 context.__teleportBuffers || (context.__teleportBuffers = {})
24 const targetBuffer = teleportBuffers[target] || (teleportBuffers[target] = [])
25 // record current index of the target buffer to handle nested teleports
26 // since the parent needs to be rendered before the child
27 const bufferIndex = targetBuffer.length
28
29 let teleportContent: SSRBufferItem
30
31 if (disabled) {
32 contentRenderFn(parentPush)
33 teleportContent = `<!--teleport start anchor--><!--teleport anchor-->`
34 } else {
35 const { getBuffer, push } = createBuffer()
36 push(`<!--teleport start anchor-->`)
37 contentRenderFn(push)
38 push(`<!--teleport anchor-->`)
39 teleportContent = getBuffer()
40 }
41
42 targetBuffer.splice(bufferIndex, 0, teleportContent)
43 if (
44 isPromise(teleportContent) ||
45 (isArray(teleportContent) && teleportContent.hasAsync)
46 ) {
47 targetBuffer.hasAsync = true
48 }
49 parentPush('<!--teleport end-->')
50}

Callers 2

renderTeleportVNodeFunction · 0.90
ssrRenderFunction · 0.90

Calls 4

createBufferFunction · 0.90
isPromiseFunction · 0.90
getBufferFunction · 0.85
pushFunction · 0.50

Tested by 1

ssrRenderFunction · 0.72