Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions src/features/sidebar/view/SecondarySplitHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ const ToggleDiffButton = ({
isDiffAvailable: boolean
}) => {
const [isMac, setIsMac] = useState(false)
// Prevent flash of button during SSR/hydration. Only render after client mount.
const [mounted, setMounted] = useState(false)
useEffect(() => {
// checkIsMac uses window so we delay the check.
const timeout = window.setTimeout(() => {
setMounted(true)
setIsMac(checkIsMac())
}, 0)
return () => window.clearTimeout(timeout)
Expand All @@ -138,6 +141,7 @@ const ToggleDiffButton = ({
: isDiffbarOpen
? "Hide changes"
: "Show changes"
if (!mounted) return null
return (
<Box sx={{ display: isSidebarTogglable ? "block" : "none" }}>

Expand Down
29 changes: 22 additions & 7 deletions src/features/sidebar/view/internal/secondary/Container.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"use client"

import { useState, useEffect } from "react"
import { SxProps } from "@mui/system"
import { Box, Stack } from "@mui/material"
import { styled } from "@mui/material/styles"
Expand All @@ -18,15 +21,23 @@ const SecondaryContainer = ({
children?: React.ReactNode,
isSM: boolean,
}) => {
// Disable transitions on initial render to prevent layout shift
const [enableTransitions, setEnableTransitions] = useState(false)
useEffect(() => {
// Enable transitions after first paint
const rafId = requestAnimationFrame(() => setEnableTransitions(true))
return () => cancelAnimationFrame(rafId)
}, [])

const sx = { overflow: "hidden" }
return (
<>
<InnerSecondaryContainer

sidebarWidth={isSM ? sidebarWidth : 0}
isSidebarOpen={isSM ? offsetContent: false}
diffWidth={isSM ? (diffWidth || 0) : 0}
isDiffOpen={isSM ? (offsetDiffContent || false) : false}
enableTransitions={enableTransitions}
sx={{ ...sx }}
>
{children}
Expand All @@ -43,19 +54,20 @@ interface WrapperStackProps {
readonly isSidebarOpen: boolean
readonly diffWidth: number
readonly isDiffOpen: boolean
readonly enableTransitions: boolean
}

const WrapperStack = styled(Stack, {
shouldForwardProp: (prop) => prop !== "isSidebarOpen" && prop !== "sidebarWidth" && prop !== "diffWidth" && prop !== "isDiffOpen"
})<WrapperStackProps>(({ theme, sidebarWidth, isSidebarOpen, diffWidth, isDiffOpen }) => {
shouldForwardProp: (prop) => prop !== "isSidebarOpen" && prop !== "sidebarWidth" && prop !== "diffWidth" && prop !== "isDiffOpen" && prop !== "enableTransitions"
})<WrapperStackProps>(({ theme, sidebarWidth, isSidebarOpen, diffWidth, isDiffOpen, enableTransitions }) => {
return {
transition: theme.transitions.create(["margin", "width"], {
transition: enableTransitions ? theme.transitions.create(["margin", "width"], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen
}),
}) : "none",
marginLeft: isSidebarOpen ? 0 : `-${sidebarWidth}px`,
marginRight: isDiffOpen ? 0 : `-${diffWidth}px`,
...((isSidebarOpen || isDiffOpen) && {
...((isSidebarOpen || isDiffOpen) && enableTransitions && {
transition: theme.transitions.create(["margin", "width"], {
easing: theme.transitions.easing.easeOut,
duration: theme.transitions.duration.enteringScreen,
Expand All @@ -69,13 +81,15 @@ const InnerSecondaryContainer = ({
isSidebarOpen,
diffWidth,
isDiffOpen,
enableTransitions,
children,
sx
}: {
sidebarWidth: number
isSidebarOpen: boolean
diffWidth: number
isDiffOpen: boolean
enableTransitions: boolean
children: React.ReactNode
sx?: SxProps
}) => {
Expand All @@ -87,8 +101,9 @@ const InnerSecondaryContainer = ({
isSidebarOpen={isSidebarOpen}
diffWidth={diffWidth}
isDiffOpen={isDiffOpen}
enableTransitions={enableTransitions}
sx={{ ...sx, width: "100%", overflowY: "auto" }}

>
<RaisedMainContent>
{children}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client'

import { useState, useEffect } from "react"
import { SxProps } from "@mui/system"
import { Drawer as MuiDrawer } from "@mui/material"
import { useTheme } from "@mui/material/styles"
Expand All @@ -15,6 +16,12 @@ const RightContainer = ({
onClose?: () => void
children?: React.ReactNode
}) => {
// Don't render drawer until client-side to prevent flash
const [mounted, setMounted] = useState(false)
useEffect(() => {
requestAnimationFrame(() => setMounted(true))
}, [])
if (!mounted) return null
return (
<>
<InnerRightContainer
Expand Down