]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip(vapor): init feature flags + set devtools when creating vapor app
authorEvan You <evan@vuejs.org>
Sat, 14 Dec 2024 08:25:35 +0000 (16:25 +0800)
committerEvan You <evan@vuejs.org>
Sat, 14 Dec 2024 08:25:35 +0000 (16:25 +0800)
packages/runtime-core/src/devtools.ts
packages/runtime-core/src/featureFlags.ts
packages/runtime-core/src/index.ts
packages/runtime-vapor/src/apiCreateApp.ts
playground/setup/dev.js

index 8b300f6955b3fdd67f717e52ace26b07c7655f60..cf7b1973c427f881eba22a3ef43e522a67273608 100644 (file)
@@ -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) => {
index 8092e8d3574af062b9c3e72523228c08dd6b1ccb..149f67512de0c071037b66e05f95257cf834b276 100644 (file)
@@ -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
 }
index 751c8b5007ff10b0e342b1ea7549000c95702c53..a4629dde8de2034a03c0175da940b8406ea63b6e 100644 (file)
@@ -542,3 +542,7 @@ export { registerHMR, unregisterHMR } from './hmr'
  * @internal
  */
 export { startMeasure, endMeasure } from './profiling'
+/**
+ * @internal
+ */
+export { initFeatureFlags } from './featureFlags'
index f88db3d32d44400a7a5ccb422bd1f68af0531938..9c77279ac467a2a6fa614ae87689c0a5c469538a 100644 (file)
@@ -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<ParentNode, VaporComponent>
 
@@ -47,6 +50,17 @@ export const createVaporApp: CreateAppFunction<ParentNode, VaporComponent> = (
   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)
 
index 01232e01d999685877236bcec4292884a3ae3ee7..ab1c59e5e598201ffa6bdc240cd45211bcb587d1 100644 (file)
@@ -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`,
         },
       }
     },