Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .claude/worktrees/fix+toggler-crash
Submodule fix+toggler-crash added at 37f728
42 changes: 26 additions & 16 deletions apps/www/public/llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3218,6 +3218,7 @@ export const AnimatedThemeToggler = ({
const [internalIsDark, setInternalIsDark] = useState(false)
const isDark = isControlled ? theme === "dark" : internalIsDark
const buttonRef = useRef<HTMLButtonElement>(null)
const isTransitioningRef = useRef(false)

useEffect(() => {
if (isControlled) return
Expand All @@ -3239,7 +3240,12 @@ export const AnimatedThemeToggler = ({

const toggleTheme = useCallback(() => {
const button = buttonRef.current
if (!button) return
if (
!button ||
isTransitioningRef.current ||
document.documentElement.dataset.magicuiThemeVt === "active"
)
return

const viewportWidth = window.visualViewport?.width ?? window.innerWidth
const viewportHeight = window.visualViewport?.height ?? window.innerHeight
Expand Down Expand Up @@ -3297,36 +3303,40 @@ export const AnimatedThemeToggler = ({
// theme unclipped between snapshot and the ready.then() JS animation.
root.style.setProperty("--magicui-theme-vt-clip-from", clipPath[0])
const cleanup = () => {
isTransitioningRef.current = false
delete root.dataset.magicuiThemeVt
root.style.removeProperty("--magicui-theme-toggle-vt-duration")
root.style.removeProperty("--magicui-theme-vt-clip-from")
}

isTransitioningRef.current = true
const transition = document.startViewTransition(() => {
flushSync(applyTheme)
})
if (typeof transition?.finished?.finally === "function") {
transition.finished.finally(cleanup)
transition.finished.finally(cleanup).catch(() => {})
} else {
cleanup()
}

const ready = transition?.ready
if (ready && typeof ready.then === "function") {
ready.then(() => {
document.documentElement.animate(
{
clipPath,
},
{
duration,
// Star: linear avoids easing overshoot that fights polygon interpolation at t→1; VT group duration is synced above.
easing: shape === "star" ? "linear" : "ease-in-out",
fill: "forwards",
pseudoElement: "::view-transition-new(root)",
}
)
})
ready
.then(() => {
document.documentElement.animate(
{
clipPath,
},
{
duration,
// Star: linear avoids easing overshoot that fights polygon interpolation at t→1; VT group duration is synced above.
easing: shape === "star" ? "linear" : "ease-in-out",
fill: "forwards",
pseudoElement: "::view-transition-new(root)",
}
)
})
.catch(() => {})
}
}, [shape, fromCenter, duration, isDark, isControlled, onThemeChange])

Expand Down
Loading