Skip to content

Commit 38d3f9a

Browse files
authored
feat(runtime-vapor): support HMR for non-compiled setup component (#13102)
1 parent 6dc07a8 commit 38d3f9a

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

packages/runtime-vapor/src/component.ts

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ export function createComponent(
188188
appContext,
189189
)
190190

191+
// HMR
192+
if (__DEV__ && component.__hmrId) {
193+
registerHMR(instance)
194+
instance.isSingleRoot = isSingleRoot
195+
instance.hmrRerender = hmrRerender.bind(null, instance)
196+
instance.hmrReload = hmrReload.bind(null, instance)
197+
}
198+
191199
if (__DEV__) {
192200
pushWarningContext(instance)
193201
startMeasure(instance, `init`)
@@ -227,14 +235,6 @@ export function createComponent(
227235
// TODO make the proxy warn non-existent property access during dev
228236
instance.setupState = proxyRefs(setupResult)
229237
devRender(instance)
230-
231-
// HMR
232-
if (component.__hmrId) {
233-
registerHMR(instance)
234-
instance.isSingleRoot = isSingleRoot
235-
instance.hmrRerender = hmrRerender.bind(null, instance)
236-
instance.hmrReload = hmrReload.bind(null, instance)
237-
}
238238
}
239239
} else {
240240
// component has a render function but no setup function
@@ -291,18 +291,33 @@ export let isApplyingFallthroughProps = false
291291
*/
292292
export function devRender(instance: VaporComponentInstance): void {
293293
instance.block =
294-
callWithErrorHandling(
295-
instance.type.render!,
296-
instance,
297-
ErrorCodes.RENDER_FUNCTION,
298-
[
299-
instance.setupState,
300-
instance.props,
301-
instance.emit,
302-
instance.attrs,
303-
instance.slots,
304-
],
305-
) || []
294+
(instance.type.render
295+
? callWithErrorHandling(
296+
instance.type.render,
297+
instance,
298+
ErrorCodes.RENDER_FUNCTION,
299+
[
300+
instance.setupState,
301+
instance.props,
302+
instance.emit,
303+
instance.attrs,
304+
instance.slots,
305+
],
306+
)
307+
: callWithErrorHandling(
308+
isFunction(instance.type) ? instance.type : instance.type.setup!,
309+
instance,
310+
ErrorCodes.SETUP_FUNCTION,
311+
[
312+
instance.props,
313+
{
314+
slots: instance.slots,
315+
attrs: instance.attrs,
316+
emit: instance.emit,
317+
expose: instance.expose,
318+
},
319+
],
320+
)) || []
306321
}
307322

308323
const emptyContext: GenericAppContext = {

0 commit comments

Comments
 (0)