Skip to content

Commit

Permalink
fix: meKeepAlive常量改为动态获取(因为@vue/share在里面删除了)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuntian001 committed Apr 3, 2023
1 parent 02d3e3d commit 6d2380d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
5 changes: 1 addition & 4 deletions src/components/meKeepAlive/core/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import {
queuePostFlushCb,
} from 'vue';
import { queueEffectWithSuspense } from './Suspense';
import {getGlobalThis} from '@vue/shared';
const globalThis = getGlobalThis();


// An object exposing the internals of a renderer, passed to tree-shakeable
// features so that they can be decoupled from this file. Keys are shortened
Expand Down Expand Up @@ -114,7 +111,7 @@ type PatchBlockChildrenFn = (

type NextFn = (vnode: VNode) => RendererNode | null;

export const queuePostRenderEffect = globalThis.__FEATURE_SUSPENSE__ ? queueEffectWithSuspense : queuePostFlushCb;
export const queuePostRenderEffect = __FEATURE_SUSPENSE__ ? queueEffectWithSuspense : queuePostFlushCb;

export type SetupRenderEffectFn = (
instance: ComponentInternalInstance,
Expand Down
8 changes: 0 additions & 8 deletions src/components/meKeepAlive/core/warning.ts

This file was deleted.

17 changes: 8 additions & 9 deletions src/components/meKeepAlive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ import {
RendererElement,
RendererNode,
setTransitionHooks,
warn,
} from 'vue';
import { getComponentName } from './core/component';
import { invokeVNodeHook } from './core/vnode';
import { warn } from './core/warning';
import { isString, isArray, invokeArrayFns,getGlobalThis } from '@vue/shared';
import { isString, isArray, invokeArrayFns } from '@vue/shared';
import { ShapeFlags } from './core/shapeFlags';
import { RendererInternals, queuePostRenderEffect, MoveType } from './core/renderer';
import { ComponentRenderContext } from './core/componentPublicInstance';
import { devtoolsComponentAdded } from './core/devtools';
import { isAsyncWrapper } from './core/apiAsyncComponent';
import { isSuspense } from './core/Suspense';
type MatchPattern = string | RegExp | Array<string | RegExp>;
const globalThis = getGlobalThis();
export interface MeKeepAliveProps {
include?: MatchPattern;
exclude?: MatchPattern;
Expand Down Expand Up @@ -77,7 +76,7 @@ const KeepAliveImpl: ComponentOptions = {

// if the internal renderer is not registered, it indicates that this is server-side rendering,
// for KeepAlive, we just need to render its children
if (globalThis.__SSR__ && !sharedContext.renderer) {
if (__SSR__ && !sharedContext.renderer) {
return () => {
const children = slots.default && slots.default();
return children && children.length === 1 ? children[0] : children;
Expand All @@ -88,7 +87,7 @@ const KeepAliveImpl: ComponentOptions = {
const keys: Keys = new Set();
let current: VNode | null = null;

if (globalThis.__DEV__ || globalThis.__FEATURE_PROD_DEVTOOLS__) {
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
(instance as any).__v_cache = cache;
}

Expand Down Expand Up @@ -120,7 +119,7 @@ const KeepAliveImpl: ComponentOptions = {
}
}, parentSuspense);

if (globalThis.__DEV__ || globalThis.__FEATURE_PROD_DEVTOOLS__) {
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
// Update components tree
devtoolsComponentAdded(instance);
}
Expand All @@ -140,7 +139,7 @@ const KeepAliveImpl: ComponentOptions = {
instance.isDeactivated = true;
}, parentSuspense);

if (globalThis.__DEV__ || globalThis.__FEATURE_PROD_DEVTOOLS__) {
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
// Update components tree
devtoolsComponentAdded(instance);
}
Expand Down Expand Up @@ -241,7 +240,7 @@ const KeepAliveImpl: ComponentOptions = {
const children = slots.default();
const rawVNode = children[0];
if (children.length > 1) {
if (globalThis.__DEV__) {
if (__DEV__) {
warn(`KeepAlive should contain exactly one component child.`, current);
}
current = null;
Expand Down Expand Up @@ -318,7 +317,7 @@ const KeepAliveImpl: ComponentOptions = {
},
};

if (globalThis.__COMPAT__) {
if (__COMPAT__) {
KeepAliveImpl.__isBuildIn = true;
}

Expand Down
10 changes: 10 additions & 0 deletions types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ declare global {
color: StringConstructor;
}>;

/* eslint-disable */
declare const __SSR__: boolean;
declare const __DEV__: boolean;
declare const __COMPAT__: boolean;

// Feature flags
declare const __FEATURE_PROD_DEVTOOLS__: boolean;
declare const __FEATURE_SUSPENSE__: boolean;
/* eslint-disable */

type ComponentProps<Component> = {
-readonly [K in keyof Omit<
InstanceType<Component>['$props'],
Expand Down
9 changes: 9 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ export default async (configEnv: ConfigEnv): Promise<UserConfigExport> => {
],
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
},
/* eslint-disable */
define: {
__SSR__: `true`,
__DEV__: configEnv.mode === 'development' ? `true` : `false`,
__COMPAT__: `false`,
__FEATURE_SUSPENSE__: `true`,
__FEATURE_PROD_DEVTOOLS__: `false`,
},
/* eslint-disable */
build: {
rollupOptions: {
output: {
Expand Down

0 comments on commit 6d2380d

Please sign in to comment.