Skip to content

Commit ae3b7cc

Browse files
committed
fix: assure body indent after redirect
1 parent 1d099d2 commit ae3b7cc

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/components/SideBar.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { platform } from 'platforms'
1010
import * as React from 'react'
1111
import { IIFC } from 'react-iifc'
1212
import { useWindowSize } from 'react-use'
13+
import { Config } from 'utils/config/helper'
1314
import { cx } from 'utils/cx'
1415
import * as DOMHelper from 'utils/DOMHelper'
1516
import * as features from 'utils/features'
@@ -179,15 +180,20 @@ function useUpdateBodyIndentOnStateUpdate(shouldExpand: boolean) {
179180
}, [sidebarToggleMode, shouldExpand])
180181
}
181182

183+
const getDerivedExpansion = ({
184+
intelligentToggle,
185+
sidebarToggleMode,
186+
}: Pick<Config, 'intelligentToggle' | 'sidebarToggleMode'>) =>
187+
sidebarToggleMode === 'persistent'
188+
? intelligentToggle === null // auto-expand checked
189+
? platform.shouldExpandSideBar()
190+
: intelligentToggle // read saved expand state
191+
: false // do not expand in float mode
192+
182193
function useGetDerivedExpansion() {
183194
const { intelligentToggle, sidebarToggleMode } = useConfigs().value
184195
return React.useCallback(
185-
() =>
186-
sidebarToggleMode === 'persistent'
187-
? intelligentToggle === null // auto-expand checked
188-
? platform.shouldExpandSideBar()
189-
: intelligentToggle // read saved expand state
190-
: false, // do not expand in float mode
196+
() => getDerivedExpansion({ intelligentToggle, sidebarToggleMode }),
191197
[intelligentToggle, sidebarToggleMode],
192198
)
193199
}
@@ -197,8 +203,12 @@ function useUpdateBodyIndentOnPJAXDone(update: (shouldExpand: boolean) => void)
197203
useOnPJAXDone(
198204
React.useCallback(() => {
199205
// check and update expand state if pinned and auto-expand checked
200-
if (sidebarToggleMode === 'persistent' && intelligentToggle === null)
201-
update(platform.shouldExpandSideBar())
206+
if (sidebarToggleMode === 'persistent') {
207+
const shouldExpand = getDerivedExpansion({ intelligentToggle, sidebarToggleMode })
208+
update(shouldExpand)
209+
// Below DOM mutation cannot be omitted, if do, body indent may get lost when shouldExpand is true for both before & after redirecting
210+
DOMHelper.setBodyIndent(shouldExpand)
211+
}
202212
}, [update, sidebarToggleMode, intelligentToggle]),
203213
)
204214
}

0 commit comments

Comments
 (0)