-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Core: Disable SidebarContextMenu in static builds #29743
Changes from 6 commits
61a7b2a
d78f58d
351b2ac
0241fb3
65161ab
60ec2fe
0768cd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import { DocsPageWrapper } from '../lib/blocks/src/components'; | |
import { isChromatic } from './isChromatic'; | ||
|
||
const { document } = global; | ||
globalThis.CONFIG_TYPE = 'DEVELOPMENT'; | ||
Comment on lines
24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: this change forces development mode for all preview environments, which may have unintended consequences for production builds |
||
|
||
const ThemeBlock = styled.div<{ side: 'left' | 'right'; layout: string }>( | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,11 @@ import type { API } from '@storybook/core/manager-api'; | |
import type { Link } from '../../../components/components/tooltip/TooltipLinkList'; | ||
import { StatusButton } from './StatusButton'; | ||
import type { ExcludesNull } from './Tree'; | ||
import { ContextMenu } from './Tree'; | ||
|
||
const empty = { | ||
onMouseEnter: () => {}, | ||
node: null, | ||
}; | ||
|
||
export const useContextMenu = (context: API_HashEntry, links: Link[], api: API) => { | ||
const [hoverCount, setHoverCount] = useState(0); | ||
|
@@ -34,7 +38,7 @@ export const useContextMenu = (context: API_HashEntry, links: Link[], api: API) | |
}, []); | ||
|
||
/** | ||
* Calculate the providerLinks whenever the user mouses over the container. We use an incrementer, | ||
* Calculate the providerLinks whenever the user mouses over the container. We use an incrementor, | ||
* instead of a simple boolean to ensure that the links are recalculated | ||
*/ | ||
const providerLinks = useMemo(() => { | ||
|
@@ -51,6 +55,11 @@ export const useContextMenu = (context: API_HashEntry, links: Link[], api: API) | |
const isRendered = providerLinks.length > 0 || links.length > 0; | ||
|
||
return useMemo(() => { | ||
// Never show the SidebarContextMenu in production | ||
if (globalThis.CONFIG_TYPE !== 'DEVELOPMENT') { | ||
return empty; | ||
} | ||
Comment on lines
+59
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider using process.env.NODE_ENV instead of globalThis.CONFIG_TYPE for more reliable environment detection |
||
|
||
return { | ||
onMouseEnter: handlers.onMouseEnter, | ||
node: isRendered ? ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: setting CONFIG_TYPE globally could affect other parts of the codebase that rely on this value. Consider using an environment variable or configuration option instead