mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
fix(vue-component-meta): fix out of memory issue
This commit is contained in:
parent
955f3071d6
commit
33b487f1e7
@ -50,6 +50,25 @@ export async function vueComponentMeta(tsconfigPath = 'tsconfig.json'): Promise<
|
||||
|
||||
const exportName = exportNames[index];
|
||||
|
||||
// we remove nested object schemas here since they are not used inside Storybook (we don't generate controls for object properties)
|
||||
// and they can cause "out of memory" issues for large/complex schemas (e.g. HTMLElement)
|
||||
// it also reduced the bundle size when running "Storybook build" when such schemas are used
|
||||
(['props', 'exposed'] as const).forEach((key) => {
|
||||
meta[key].forEach((value) => {
|
||||
if (typeof value.schema !== 'object') return;
|
||||
|
||||
// we need to use Object.defineProperty here since schema is a getter so we can not set it directly
|
||||
Object.defineProperty(value, 'schema', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
value: {
|
||||
kind: value.schema.kind,
|
||||
type: value.schema.type,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const exposed =
|
||||
// the meta also includes duplicated entries in the "exposed" array with "on"
|
||||
// prefix (e.g. onClick instead of click), so we need to filter them out here
|
||||
|
@ -1,3 +1,4 @@
|
||||
import type { VueDocgenInfo, VueDocgenInfoEntry, VueDocgenPlugin } from '@storybook/vue3-vite';
|
||||
import type { ExtractedProp } from 'storybook/internal/docs-tools';
|
||||
import {
|
||||
convert,
|
||||
@ -6,7 +7,6 @@ import {
|
||||
type ArgTypesExtractor,
|
||||
} from 'storybook/internal/docs-tools';
|
||||
import type { SBType, StrictArgTypes, StrictInputType } from 'storybook/internal/types';
|
||||
import type { VueDocgenInfo, VueDocgenInfoEntry, VueDocgenPlugin } from '@storybook/vue3-vite';
|
||||
|
||||
type PropertyMetaSchema = VueDocgenInfoEntry<'vue-component-meta', 'props'>['schema'];
|
||||
|
||||
@ -283,17 +283,11 @@ export const convertVueComponentMetaProp = (
|
||||
};
|
||||
}
|
||||
|
||||
// recursively/deeply convert all properties of the object
|
||||
case 'object':
|
||||
return {
|
||||
name: 'object',
|
||||
value: Object.entries(schema.schema ?? {}).reduce<Record<string, SBType>>(
|
||||
(obj, [propName, propSchema]) => {
|
||||
obj[propName] = convertVueComponentMetaProp(propSchema);
|
||||
return obj;
|
||||
},
|
||||
{}
|
||||
),
|
||||
// Storybook does not generate controls for object properties so we don't need to recursively map the object schema here
|
||||
value: {},
|
||||
required,
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user