Skip to content

Commit 76e8d2c

Browse files
committed
wip(vapor): init feature flags + set devtools when creating vapor app
1 parent c07734d commit 76e8d2c

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

packages/runtime-core/src/devtools.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ function emit(event: string, ...args: any[]) {
4949
}
5050
}
5151

52+
let queued = false
5253
export function setDevtoolsHook(hook: DevtoolsHook, target: any): void {
54+
if (devtoolsNotInstalled || queued) {
55+
return
56+
}
5357
devtools = hook
5458
if (devtools) {
5559
devtools.enabled = true
@@ -66,6 +70,7 @@ export function setDevtoolsHook(hook: DevtoolsHook, target: any): void {
6670
// eslint-disable-next-line no-restricted-syntax
6771
!window.navigator?.userAgent?.includes('jsdom')
6872
) {
73+
queued = true
6974
const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
7075
target.__VUE_DEVTOOLS_HOOK_REPLAY__ || [])
7176
replay.push((newHook: DevtoolsHook) => {

packages/runtime-core/src/featureFlags.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { getGlobalThis } from '@vue/shared'
22

3+
let initialized = false
4+
35
/**
46
* This is only called in esm-bundler builds.
57
* It is called when a renderer is created, in `baseCreateRenderer` so that
68
* importing runtime-core is side-effects free.
79
*/
810
export function initFeatureFlags(): void {
11+
if (initialized) return
12+
913
const needWarn = []
1014

1115
if (typeof __FEATURE_OPTIONS_API__ !== 'boolean') {
@@ -35,4 +39,6 @@ export function initFeatureFlags(): void {
3539
`For more details, see https://link.vuejs.org/feature-flags.`,
3640
)
3741
}
42+
43+
initialized = true
3844
}

packages/runtime-core/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,3 +542,7 @@ export { registerHMR, unregisterHMR } from './hmr'
542542
* @internal
543543
*/
544544
export { startMeasure, endMeasure } from './profiling'
545+
/**
546+
* @internal
547+
*/
548+
export { initFeatureFlags } from './featureFlags'

packages/runtime-vapor/src/apiCreateApp.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import {
1212
type CreateAppFunction,
1313
createAppAPI,
1414
flushOnAppMount,
15+
initFeatureFlags,
1516
normalizeContainer,
17+
setDevtoolsHook,
1618
warn,
1719
} from '@vue/runtime-dom'
1820
import type { RawProps } from './componentProps'
21+
import { getGlobalThis } from '@vue/shared'
1922

2023
let _createApp: CreateAppFunction<ParentNode, VaporComponent>
2124

@@ -47,6 +50,17 @@ export const createVaporApp: CreateAppFunction<ParentNode, VaporComponent> = (
4750
comp,
4851
props,
4952
) => {
53+
// compile-time feature flags check
54+
if (__ESM_BUNDLER__ && !__TEST__) {
55+
initFeatureFlags()
56+
}
57+
58+
const target = getGlobalThis()
59+
target.__VUE__ = true
60+
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
61+
setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target)
62+
}
63+
5064
if (!_createApp) _createApp = createAppAPI(mountApp, unmountApp, getExposed)
5165
const app = _createApp(comp, props)
5266

playground/setup/dev.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export function DevPlugin({ browser = false } = {}) {
5858
__FEATURE_SUSPENSE__: `true`,
5959
__FEATURE_OPTIONS_API__: `true`,
6060
__FEATURE_PROD_DEVTOOLS__: `false`,
61+
__FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__: `false`,
6162
},
6263
}
6364
},

0 commit comments

Comments
 (0)