|
1 | 1 | import { EMPTY_OBJ, NO, hasOwn, isArray, isFunction } from '@vue/shared' |
2 | | -import { type Block, type BlockFn, DynamicFragment, insert } from './block' |
| 2 | +import { |
| 3 | + type Block, |
| 4 | + type BlockFn, |
| 5 | + DynamicFragment, |
| 6 | + insert, |
| 7 | + setScopeId, |
| 8 | +} from './block' |
3 | 9 | import { rawPropsProxyHandlers } from './componentProps' |
4 | | -import { currentInstance, isRef } from '@vue/runtime-dom' |
| 10 | +import { |
| 11 | + type GenericComponentInstance, |
| 12 | + currentInstance, |
| 13 | + isRef, |
| 14 | + setCurrentRenderingInstance, |
| 15 | +} from '@vue/runtime-dom' |
5 | 16 | import type { LooseRawProps, VaporComponentInstance } from './component' |
6 | 17 | import { renderEffect } from './renderEffect' |
7 | 18 | import { insertionAnchor, insertionParent } from './insertionState' |
@@ -97,6 +108,22 @@ export function forwardedSlotCreator(): ( |
97 | 108 | createSlot(name, rawProps, fallback, instance) |
98 | 109 | } |
99 | 110 |
|
| 111 | +export function withVaporCtx( |
| 112 | + fn: Function, |
| 113 | + ctx: GenericComponentInstance | null = currentInstance, |
| 114 | +): () => Block { |
| 115 | + return (...args: any[]): Block => { |
| 116 | + const prevInstance = setCurrentRenderingInstance(ctx as any) |
| 117 | + let res |
| 118 | + try { |
| 119 | + res = fn(...args) |
| 120 | + } finally { |
| 121 | + setCurrentRenderingInstance(prevInstance) |
| 122 | + } |
| 123 | + return res |
| 124 | + } |
| 125 | +} |
| 126 | + |
100 | 127 | export function createSlot( |
101 | 128 | name: string | (() => string), |
102 | 129 | rawProps?: LooseRawProps | null, |
@@ -156,6 +183,9 @@ export function createSlot( |
156 | 183 | } |
157 | 184 | } |
158 | 185 |
|
| 186 | + const scopeId = instance.type.__scopeId |
| 187 | + if (scopeId) setScopeId(fragment, `${scopeId}-s`) |
| 188 | + |
159 | 189 | if (!isHydrating && _insertionParent) { |
160 | 190 | insert(fragment, _insertionParent, _insertionAnchor) |
161 | 191 | } |
|
0 commit comments