packages/codemod/docs/PORTAL_MIGRATION.md
This document outlines the migration of Portal-related components from Chakra UI v2 to v3.
| v2 Component | v3 Component | Notes |
|---|---|---|
Portal | Portal | Same component, props simplified |
PortalManager | ❌ | Removed (no longer needed) |
v2:
import { Portal, PortalManager } from "@chakra-ui/react"
v3:
import { Portal } from "@chakra-ui/react"
| v2 Prop | v3 Prop | Notes |
|---|---|---|
containerRef | ✅ | Unchanged |
appendToParentPortal | ❌ | Removed |
v2:
import { Portal } from "@chakra-ui/react"
;<Portal>
<Box bg="red.500">This renders in a portal</Box>
</Portal>
v3:
import { Portal } from "@chakra-ui/react"
;<Portal>
<Box bg="red.500">This renders in a portal</Box>
</Portal>
v2:
import { Portal } from "@chakra-ui/react"
function Demo() {
const ref = useRef(null)
return (
<>
<div ref={ref} />
<Portal containerRef={ref}>
<Box>Portaled content</Box>
</Portal>
</>
)
}
v3:
import { Portal } from "@chakra-ui/react"
function Demo() {
const ref = useRef(null)
return (
<>
<div ref={ref} />
<Portal containerRef={ref}>
<Box>Portaled content</Box>
</Portal>
</>
)
}
v2:
import { PortalManager } from "@chakra-ui/react"
function App() {
return (
<PortalManager>
<YourApp />
</PortalManager>
)
}
v3:
// Simply remove PortalManager wrapper
function App() {
return <YourApp />
}
To automatically migrate your Portal components, run:
npx @chakra-ui/codemod transform portal <path>
# Transform all files in src directory
npx @chakra-ui/codemod transform portal ./src
# Dry run to preview changes
npx @chakra-ui/codemod transform portal ./src --dry
If you prefer to migrate manually:
PortalManager wrappers and importsPortal
componentsPortalManager - No longer needed in v3; portals are managed automaticallyappendToParentPortal on Portal - Portal nesting is now handled
automaticallyThe v3 Portal provides:
PortalManager wrapper