mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: detect redirect the dumb way
This commit is contained in:
parent
30382b39d8
commit
1b9317791d
1 changed files with 12 additions and 3 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { useConfigs } from 'containers/ConfigsContext'
|
||||
import { platform } from 'platforms'
|
||||
import * as React from 'react'
|
||||
import { useEvent } from 'react-use'
|
||||
import { useEvent, useInterval } from 'react-use'
|
||||
|
||||
const config: import('pjax-api').Config = {
|
||||
areas: [
|
||||
|
|
@ -54,8 +54,17 @@ export const loadWithFastRedirect = (url: string, element: HTMLElement) => {
|
|||
}
|
||||
|
||||
export function useAfterRedirect(callback: () => void) {
|
||||
useEvent('pjax:end', callback, document) // legacy support
|
||||
useEvent('turbo:render', callback, document) // prevent page content shift after first redirect to new page via turbo when sidebar is pinned
|
||||
const latestHref = React.useRef(location.href)
|
||||
const raceCallback = React.useCallback(() => {
|
||||
const { href } = location
|
||||
if (latestHref.current !== href) {
|
||||
latestHref.current = href
|
||||
callback()
|
||||
}
|
||||
}, [callback])
|
||||
useInterval(raceCallback, 500)
|
||||
useEvent('pjax:end', raceCallback, document) // legacy support
|
||||
useEvent('turbo:render', raceCallback, document) // prevent page content shift after first redirect to new page via turbo when sidebar is pinned
|
||||
}
|
||||
|
||||
export function useRedirectedEvents(
|
||||
|
|
|
|||
Loading…
Reference in a new issue