File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import Typography from '@mui/material/Typography';
44import Divider from '@mui/material/Divider' ;
55import { styled } from 'storybook/internal/theming' ;
66import { RichTreeView } from '@mui/x-tree-view/RichTreeView' ;
7- import { useParameter } from 'storybook/manager-api' ;
7+ import { useParameter } from '@ storybook/manager-api' ;
88
99interface TreeNode {
1010 id : string ;
@@ -85,8 +85,8 @@ export const Tab: React.FC = () => {
8585 const currentStoryPath = useParameter < string > ( 'story_absolute_path' ) ;
8686
8787 const { dependencies, dependants, dependenciesExpandedIds, dependantsExpandedIds } = useMemo ( ( ) => {
88- const dependencyTreeObj = JSON . parse ( localStorage . getItem ( 'dependencyTreeObj' ) || '{}' ) ;
89- const dependantsTreeObj = JSON . parse ( localStorage . getItem ( 'dependantsTreeObj' ) || '{}' ) ;
88+ const dependencyTreeObj = ( ( window as any ) . __STORYBOOK_DEPENDENCY_TREE__ as Record < string , object > ) || { } ;
89+ const dependantsTreeObj = ( ( window as any ) . __STORYBOOK_DEPENDANTS_TREE__ as Record < string , object > ) || { } ;
9090
9191 const depsSource = dependencyTreeObj [ currentStoryPath ] || { } ;
9292 const mainComponentPath = Object . keys ( depsSource ) [ 0 ] ;
Original file line number Diff line number Diff line change @@ -158,8 +158,12 @@ export function vitePreTreeDependencyPlugin(config: ViteConfig): Plugin {
158158
159159 const dependantsTreeObj = buildDependantsFromDependencyTree ( dependencyTreeObj ) ;
160160
161- newSource += `\nlocalStorage.setItem("dependencyTreeObj", '${ JSON . stringify ( dependencyTreeObj ) } ');` ;
162- newSource += `\nlocalStorage.setItem("dependantsTreeObj", '${ JSON . stringify ( dependantsTreeObj ) } ');` ;
161+ newSource += "\ntry {" ;
162+ newSource += "\n if (typeof window !== 'undefined' && window.parent) {" ;
163+ newSource += `\n window.parent.__STORYBOOK_DEPENDENCY_TREE__ = ${ JSON . stringify ( dependencyTreeObj ) } ;` ;
164+ newSource += `\n window.parent.__STORYBOOK_DEPENDANTS_TREE__ = ${ JSON . stringify ( dependantsTreeObj ) } ;` ;
165+ newSource += "\n }" ;
166+ newSource += "\n} catch (e) { console.warn('Failed to set window.parent globals for dependency tree', e); }" ;
163167 }
164168
165169 return { code : newSource , map : null } ;
You can’t perform that action at this time.
0 commit comments