Skip to content

Commit da5943d

Browse files
authored
fix: remove <ConditionalWrapper> (#1439)
1 parent 80b8555 commit da5943d

File tree

7 files changed

+80
-64
lines changed

7 files changed

+80
-64
lines changed

.storybook/main.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {StorybookConfig} from '@storybook/react-vite'
2+
import viteReact from '@vitejs/plugin-react'
23
import {mergeConfig} from 'vite'
34
import tsconfigPaths from 'vite-tsconfig-paths'
45

@@ -22,7 +23,12 @@ const config: StorybookConfig = {
2223
},
2324
viteFinal(config) {
2425
return mergeConfig(config, {
25-
plugins: [tsconfigPaths()],
26+
plugins: [
27+
viteReact({
28+
babel: {plugins: [['babel-plugin-react-compiler', {target: '18'}]]},
29+
}),
30+
tsconfigPaths(),
31+
],
2632
})
2733
},
2834
}

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@
152152
"@types/refractor": "^3.4.1",
153153
"@typescript-eslint/eslint-plugin": "^7.18.0",
154154
"@typescript-eslint/parser": "^7.18.0",
155+
"@vitejs/plugin-react": "^4.3.3",
156+
"babel-plugin-react-compiler": "beta",
155157
"commitizen": "^4.3.0",
156158
"cypress": "^13.13.2",
157159
"cypress-real-events": "^1.13.0",
@@ -176,6 +178,7 @@
176178
"npm-run-all2": "^5.0.2",
177179
"prettier": "^3.3.3",
178180
"react": "^18.3.1",
181+
"react-compiler-runtime": "beta",
179182
"react-dom": "^18.3.1",
180183
"react-is": "^18.3.1",
181184
"refractor": "^4.8.1",

pnpm-lock.yaml

+41-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/primitives/popover/popover.tsx

+10-24
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@ import {useArrayProp, useElementSize, useMediaIndex, usePrefersReducedMotion} fr
2828
import {origin} from '../../middleware/origin'
2929
import {useTheme_v2} from '../../theme'
3030
import {BoxOverflow, CardTone, Placement, PopoverMargins} from '../../types'
31-
import {
32-
ConditionalWrapper,
33-
LayerProps,
34-
LayerProvider,
35-
Portal,
36-
useBoundaryElement,
37-
} from '../../utils'
31+
import {LayerProps, LayerProvider, Portal, useBoundaryElement} from '../../utils'
3832
import {ResponsiveRadiusProps, ResponsiveShadowProps} from '../types'
3933
import {
4034
DEFAULT_POPOVER_DISTANCE,
@@ -427,26 +421,18 @@ export const Popover = memo(
427421
</LayerProvider>
428422
)
429423

424+
const children =
425+
open &&
426+
(portal ? (
427+
<Portal __unstable_name={typeof portal === 'string' ? portal : undefined}>{popover}</Portal>
428+
) : (
429+
popover
430+
))
431+
430432
return (
431433
<>
432434
{/* the popover */}
433-
<ConditionalWrapper
434-
condition={animate}
435-
wrapper={(children) => <AnimatePresence>{children}</AnimatePresence>}
436-
>
437-
{open && (
438-
<ConditionalWrapper
439-
condition={!!portal}
440-
wrapper={(children) => (
441-
<Portal __unstable_name={typeof portal === 'string' ? portal : undefined}>
442-
{children}
443-
</Portal>
444-
)}
445-
>
446-
{popover}
447-
</ConditionalWrapper>
448-
)}
449-
</ConditionalWrapper>
435+
{animate ? <AnimatePresence>{children}</AnimatePresence> : children}
450436

451437
{/* the referred element */}
452438
{child}

src/core/primitives/tooltip/tooltip.tsx

+12-25
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,7 @@ import {useDelayedState} from '../../hooks/useDelayedState'
3030
import {origin} from '../../middleware/origin'
3131
import {useTheme_v2} from '../../theme'
3232
import type {Placement} from '../../types'
33-
import {
34-
ConditionalWrapper,
35-
Layer,
36-
type LayerProps,
37-
Portal,
38-
useBoundaryElement,
39-
usePortal,
40-
} from '../../utils'
33+
import {Layer, type LayerProps, Portal, useBoundaryElement, usePortal} from '../../utils'
4134
import type {Delay} from '../types'
4235
import {
4336
DEFAULT_FALLBACK_PLACEMENTS,
@@ -403,26 +396,20 @@ export const Tooltip = forwardRef(function Tooltip(
403396
</Root>
404397
)
405398

399+
const children =
400+
showTooltip &&
401+
(portalProp ? (
402+
<Portal __unstable_name={typeof portalProp === 'string' ? portalProp : undefined}>
403+
{tooltip}
404+
</Portal>
405+
) : (
406+
tooltip
407+
))
408+
406409
return (
407410
<>
408411
{/* the tooltip */}
409-
<ConditionalWrapper
410-
condition={animate}
411-
wrapper={(children) => <AnimatePresence>{children}</AnimatePresence>}
412-
>
413-
{showTooltip && (
414-
<ConditionalWrapper
415-
condition={!!portalProp}
416-
wrapper={(children) => (
417-
<Portal __unstable_name={typeof portalProp === 'string' ? portalProp : undefined}>
418-
{children}
419-
</Portal>
420-
)}
421-
>
422-
{tooltip}
423-
</ConditionalWrapper>
424-
)}
425-
</ConditionalWrapper>
412+
{animate ? <AnimatePresence>{children}</AnimatePresence> : children}
426413

427414
{/* the referred element */}
428415
{child}

src/core/utils/conditionalWrapper/conditionalWrapper.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* @internal
3+
* @deprecated this component will be removed in the next major release
34
*/
45
export function ConditionalWrapper({
56
children,

workshop.runtime.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import path from 'path'
22
import {defineRuntime} from '@sanity/ui-workshop'
3+
import viteReact from '@vitejs/plugin-react'
34

45
const EXPORTS_PATH = path.resolve(__dirname, 'exports')
56

67
export default defineRuntime({
78
vite: (viteConfig) => ({
89
...viteConfig,
10+
plugins: [
11+
viteReact({
12+
babel: {plugins: [['babel-plugin-react-compiler', {target: '18'}]]},
13+
}),
14+
],
915
resolve: {
1016
...viteConfig.resolve,
1117
alias: {

0 commit comments

Comments
 (0)