Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: vue received a Component that was made a reactive object #4367

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/@core/base/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"dependencies": {
"@ctrl/tinycolor": "^4.1.0",
"@tanstack/vue-store": "^0.5.5",
"@vue/reactivity": "^3.5.4",
"@vue/shared": "^3.5.4",
"clsx": "^2.1.1",
"defu": "^6.1.4",
Expand Down
1 change: 1 addition & 0 deletions packages/@core/base/shared/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './inference';
export * from './letter';
export * from './merge';
export * from './nprogress';
export * from './reactivity';
export * from './state-handler';
export * from './to';
export * from './tree';
Expand Down
26 changes: 26 additions & 0 deletions packages/@core/base/shared/src/utils/reactivity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { isProxy, isReactive, isRef, toRaw } from '@vue/reactivity';

function deepToRaw<T extends Record<string, any>>(sourceObj: T): T {
const objectIterator = (input: any): any => {
if (Array.isArray(input)) {
return input.map((item) => objectIterator(item));
}
if (isRef(input) || isReactive(input) || isProxy(input)) {
return objectIterator(toRaw(input));
}
if (input && typeof input === 'object') {
const result = {} as T;
for (const key in input) {
if (Object.prototype.hasOwnProperty.call(input, key)) {
result[key as keyof T] = objectIterator(input[key]);
}
}
return result;
}
return input;
};

return objectIterator(sourceObj);
}

export { deepToRaw };
1 change: 1 addition & 0 deletions packages/@core/ui-kit/tabs-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@vben-core/composables": "workspace:*",
"@vben-core/icons": "workspace:*",
"@vben-core/shadcn-ui": "workspace:*",
"@vben-core/shared": "workspace:*",
"@vben-core/typings": "workspace:*",
"@vueuse/core": "^11.0.3",
"vue": "^3.5.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { computed, ref } from 'vue';

import { Pin, X } from '@vben-core/icons';
import { VbenContextMenu, VbenIcon } from '@vben-core/shadcn-ui';
import { deepToRaw } from '@vben-core/shared/utils';

interface Props extends TabsProps {}

Expand Down Expand Up @@ -40,7 +41,8 @@ const style = computed(() => {
});

const tabsView = computed((): TabConfig[] => {
return props.tabs.map((tab) => {
return props.tabs.map((_tab) => {
const tab = deepToRaw(_tab);
return {
...tab,
affixTab: !!tab.meta?.affixTab,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { computed } from 'vue';

import { Pin, X } from '@vben-core/icons';
import { VbenContextMenu, VbenIcon } from '@vben-core/shadcn-ui';
import { deepToRaw } from '@vben-core/shared/utils';

interface Props extends TabsProps {}

Expand Down Expand Up @@ -46,7 +47,8 @@ const typeWithClass = computed(() => {
});

const tabsView = computed((): TabConfig[] => {
return props.tabs.map((tab) => {
return props.tabs.map((_tab) => {
const tab = deepToRaw(_tab);
return {
...tab,
affixTab: !!tab.meta?.affixTab,
Expand Down
4 changes: 2 additions & 2 deletions packages/effects/layouts/src/basic/layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
usePreferences,
} from '@vben/preferences';
import { useLockStore, useUserStore } from '@vben/stores';
import { mapTree } from '@vben/utils';
import { deepToRaw, mapTree } from '@vben/utils';
import { VbenAdminLayout } from '@vben-core/layout-ui';
import { Toaster, VbenBackTop, VbenLogo } from '@vben-core/shadcn-ui';

Expand Down Expand Up @@ -113,7 +113,7 @@ const {

function wrapperMenus(menus: MenuRecordRaw[]) {
return mapTree(menus, (item) => {
return { ...item, name: $t(item.name) };
return { ...deepToRaw(item), name: $t(item.name) };
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/effects/layouts/src/basic/menu/menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { MenuProps } from '@vben-core/menu-ui';
import { Menu } from '@vben-core/menu-ui';

interface Props extends MenuProps {
menus?: MenuRecordRaw[];
menus: MenuRecordRaw[];
}

const props = withDefaults(defineProps<Props>(), {
Expand Down
Loading