Skip to content

Commit 5ef769b

Browse files
authored
test(hmr): port hmr tests (#14109)
1 parent 005ba04 commit 5ef769b

File tree

7 files changed

+1038
-47
lines changed

7 files changed

+1038
-47
lines changed

packages/compiler-vapor/src/generators/component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { genEventHandler } from './event'
4040
import { genDirectiveModifiers, genDirectivesForElement } from './directive'
4141
import { genBlock } from './block'
4242
import { genModelHandler } from './vModel'
43-
import { isBuiltInComponent } from '../utils'
43+
import { isBuiltInComponent, isKeepAliveTag } from '../utils'
4444

4545
export function genCreateComponent(
4646
operation: CreateComponentIRNode,
@@ -460,7 +460,7 @@ function genSlotBlockWithProps(oper: SlotBlockIRNode, context: CodegenContext) {
460460
]
461461
}
462462

463-
if (node.type === NodeTypes.ELEMENT) {
463+
if (node.type === NodeTypes.ELEMENT && !isKeepAliveTag(node.tag)) {
464464
// wrap with withVaporCtx to ensure correct currentInstance inside slot
465465
blockFn = [`${context.helper('withVaporCtx')}(`, ...blockFn, `)`]
466466
}

packages/runtime-core/src/hmr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function rerender(id: string, newRender?: Function): void {
9797
// this flag forces child components with slot content to update
9898
isHmrUpdating = true
9999
if (instance.vapor) {
100-
instance.hmrRerender!()
100+
if (!instance.isUnmounted) instance.hmrRerender!()
101101
} else {
102102
const i = instance as ComponentInternalInstance
103103
// #13771 don't update if the job is already disposed

packages/runtime-vapor/__tests__/_utils.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import { createVaporApp, vaporInteropPlugin } from '../src'
22
import { type App, type Component, createApp } from '@vue/runtime-dom'
3-
import type { VaporComponent, VaporComponentInstance } from '../src/component'
3+
import type {
4+
ObjectVaporComponent,
5+
VaporComponent,
6+
VaporComponentInstance,
7+
} from '../src/component'
48
import type { RawProps } from '../src/componentProps'
59
import { compileScript, parse } from '@vue/compiler-sfc'
610
import * as runtimeVapor from '../src'
711
import * as runtimeDom from '@vue/runtime-dom'
812
import * as VueServerRenderer from '@vue/server-renderer'
13+
import {
14+
type CompilerOptions,
15+
compile as compileVapor,
16+
} from '@vue/compiler-vapor'
917

1018
export interface RenderContext {
1119
component: VaporComponent
@@ -187,6 +195,29 @@ export function compile(
187195
)
188196
}
189197

198+
export function compileToVaporRender(
199+
template: string,
200+
options?: CompilerOptions,
201+
): ObjectVaporComponent['render'] {
202+
let { code } = compileVapor(template, {
203+
mode: 'module',
204+
prefixIdentifiers: true,
205+
hmr: true,
206+
...options,
207+
})
208+
209+
const transformed = code
210+
.replace(/\bimport {/g, 'const {')
211+
.replace(/ as _/g, ': _')
212+
.replace(/} from ['"]vue['"];/g, '} = Vue;')
213+
.replace(/export function render/, 'function render')
214+
215+
return new Function('Vue', `${transformed}\nreturn render`)({
216+
...runtimeDom,
217+
...runtimeVapor,
218+
})
219+
}
220+
190221
export function shuffle(array: Array<any>): any[] {
191222
let currentIndex = array.length
192223
let temporaryValue

0 commit comments

Comments
 (0)