From: Evan You Date: Sat, 14 Dec 2024 08:25:35 +0000 (+0800) Subject: wip(vapor): init feature flags + set devtools when creating vapor app X-Git-Tag: v3.6.0-alpha.1~16^2~148 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=76e8d2c4d0c23534509b62f638bcdb8e7853af07;p=thirdparty%2Fvuejs%2Fcore.git wip(vapor): init feature flags + set devtools when creating vapor app --- diff --git a/packages/runtime-core/src/devtools.ts b/packages/runtime-core/src/devtools.ts index 8b300f6955..cf7b1973c4 100644 --- a/packages/runtime-core/src/devtools.ts +++ b/packages/runtime-core/src/devtools.ts @@ -49,7 +49,11 @@ function emit(event: string, ...args: any[]) { } } +let queued = false export function setDevtoolsHook(hook: DevtoolsHook, target: any): void { + if (devtoolsNotInstalled || queued) { + return + } devtools = hook if (devtools) { devtools.enabled = true @@ -66,6 +70,7 @@ export function setDevtoolsHook(hook: DevtoolsHook, target: any): void { // eslint-disable-next-line no-restricted-syntax !window.navigator?.userAgent?.includes('jsdom') ) { + queued = true const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ = target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []) replay.push((newHook: DevtoolsHook) => { diff --git a/packages/runtime-core/src/featureFlags.ts b/packages/runtime-core/src/featureFlags.ts index 8092e8d357..149f67512d 100644 --- a/packages/runtime-core/src/featureFlags.ts +++ b/packages/runtime-core/src/featureFlags.ts @@ -1,11 +1,15 @@ import { getGlobalThis } from '@vue/shared' +let initialized = false + /** * This is only called in esm-bundler builds. * It is called when a renderer is created, in `baseCreateRenderer` so that * importing runtime-core is side-effects free. */ export function initFeatureFlags(): void { + if (initialized) return + const needWarn = [] if (typeof __FEATURE_OPTIONS_API__ !== 'boolean') { @@ -35,4 +39,6 @@ export function initFeatureFlags(): void { `For more details, see https://link.vuejs.org/feature-flags.`, ) } + + initialized = true } diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 751c8b5007..a4629dde8d 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -542,3 +542,7 @@ export { registerHMR, unregisterHMR } from './hmr' * @internal */ export { startMeasure, endMeasure } from './profiling' +/** + * @internal + */ +export { initFeatureFlags } from './featureFlags' diff --git a/packages/runtime-vapor/src/apiCreateApp.ts b/packages/runtime-vapor/src/apiCreateApp.ts index f88db3d32d..9c77279ac4 100644 --- a/packages/runtime-vapor/src/apiCreateApp.ts +++ b/packages/runtime-vapor/src/apiCreateApp.ts @@ -12,10 +12,13 @@ import { type CreateAppFunction, createAppAPI, flushOnAppMount, + initFeatureFlags, normalizeContainer, + setDevtoolsHook, warn, } from '@vue/runtime-dom' import type { RawProps } from './componentProps' +import { getGlobalThis } from '@vue/shared' let _createApp: CreateAppFunction @@ -47,6 +50,17 @@ export const createVaporApp: CreateAppFunction = ( comp, props, ) => { + // compile-time feature flags check + if (__ESM_BUNDLER__ && !__TEST__) { + initFeatureFlags() + } + + const target = getGlobalThis() + target.__VUE__ = true + if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) { + setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target) + } + if (!_createApp) _createApp = createAppAPI(mountApp, unmountApp, getExposed) const app = _createApp(comp, props) diff --git a/playground/setup/dev.js b/playground/setup/dev.js index 01232e01d9..ab1c59e5e5 100644 --- a/playground/setup/dev.js +++ b/playground/setup/dev.js @@ -58,6 +58,7 @@ export function DevPlugin({ browser = false } = {}) { __FEATURE_SUSPENSE__: `true`, __FEATURE_OPTIONS_API__: `true`, __FEATURE_PROD_DEVTOOLS__: `false`, + __FEATURE_PROD_HYDRATION_MISMATCH_DETAILS__: `false`, }, } },