mirror of
https://github.com/TabbyML/tabby
synced 2024-11-22 00:08:06 +00:00
fix(ui): fix useHash hook, do not use next/router (#2503)
* fix(ui): fix useHash hook, do not use next/router * update * update * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
b3be6bbc1d
commit
9d2a193914
@ -59,7 +59,7 @@ export const ChatSideBar: React.FC<ChatSideBarProps> = ({
|
|||||||
),
|
),
|
||||||
{
|
{
|
||||||
hash: lineHash,
|
hash: lineHash,
|
||||||
replace: true
|
replace: false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
25
ee/tabby-ui/lib/hooks/use-hash.ts
vendored
25
ee/tabby-ui/lib/hooks/use-hash.ts
vendored
@ -1,9 +1,10 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import Router from 'next/router'
|
import { useParams } from 'next/navigation'
|
||||||
|
|
||||||
import { useLatest } from './use-latest'
|
import { useLatest } from './use-latest'
|
||||||
|
|
||||||
export function useHash(): [string, (hash: string) => void] {
|
export function useHash(): [string, (hash: string) => void] {
|
||||||
|
const param = useParams()
|
||||||
const [hash, setHash] = React.useState<string>('')
|
const [hash, setHash] = React.useState<string>('')
|
||||||
const hashRef = useLatest(hash)
|
const hashRef = useLatest(hash)
|
||||||
|
|
||||||
@ -11,22 +12,22 @@ export function useHash(): [string, (hash: string) => void] {
|
|||||||
window.location.hash = hash
|
window.location.hash = hash
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
React.useEffect(() => {
|
const handleHashChange = () => {
|
||||||
const handleHashChange = () => {
|
const newHash = window.location.hash
|
||||||
const newHash = window.location.hash
|
if (hashRef.current !== newHash) {
|
||||||
if (hashRef.current !== newHash) {
|
setHash(newHash)
|
||||||
setHash(newHash)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleHashChange()
|
React.useEffect(() => {
|
||||||
|
window.addEventListener('hashchange', handleHashChange)
|
||||||
Router.events.on('hashChangeComplete', handleHashChange)
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
Router.events.off('hashChangeComplete', handleHashChange)
|
window.removeEventListener('hashchange', handleHashChange)
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
// Handle hash changes from next/navigation
|
||||||
|
React.useEffect(handleHashChange, [param])
|
||||||
|
|
||||||
return [hash, changeHash]
|
return [hash, changeHash]
|
||||||
}
|
}
|
||||||
|
8
rules/do-not-use-next-pages.yml
Normal file
8
rules/do-not-use-next-pages.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
id: do-not-use-next-pages
|
||||||
|
message: Don't use next pages routing as we're fully commited to app router.
|
||||||
|
severity: error
|
||||||
|
language: typescript
|
||||||
|
files:
|
||||||
|
- ./ee/tabby-ui/**
|
||||||
|
rule:
|
||||||
|
pattern: import $$$ from 'next/router'
|
Loading…
Reference in New Issue
Block a user