Skip to content

Commit

Permalink
fix: remove route state replace
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jan 24, 2024
1 parent 613d684 commit acc815e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ next-env.d.ts
.env
.idea


.vscode/sftp.json

src/app/dev
17 changes: 1 addition & 16 deletions src/components/modules/peek/NotePreview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useQuery } from '@tanstack/react-query'
import { useEffect, useMemo } from 'react'
import { useMemo } from 'react'
import { atom } from 'jotai'
import type { NoteWrappedPayload } from '@mx-space/api-client'
import type { FC } from 'react'
Expand Down Expand Up @@ -36,21 +36,6 @@ export const NotePreview: FC<NotePreviewProps> = (props) => {
...queries.note.byNid(props.noteId.toString()),
})

useEffect(() => {
const currentState = history.state
const currentLocation = window.location.href
const nextUrl = new URL(currentLocation)
nextUrl.pathname = `/notes/${props.noteId}`
const nextUrlString = nextUrl.href

// 虽然但是,这样浏览器的前进后退会有问题
// 如果用 NextJS 的 parallel-routes 情况太复杂
history.replaceState(null, '', nextUrlString)
return () => {
history.replaceState(currentState, '', currentLocation)
}
}, [props.noteId])

const overrideAtom = useMemo(() => atom(null! as NoteWrappedPayload), [])
if (isLoading) return <Loading className="w-full" useDefaultLoadingText />
if (!data) return null
Expand Down
17 changes: 1 addition & 16 deletions src/components/modules/peek/PostPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useQuery } from '@tanstack/react-query'
import { useEffect, useMemo } from 'react'
import { useMemo } from 'react'
import Balancer from 'react-wrap-balancer'
import { atom } from 'jotai'
import type { PostModel } from '@mx-space/api-client'
Expand Down Expand Up @@ -34,21 +34,6 @@ export const PostPreview: FC<PostPreviewProps> = (props) => {
...queries.post.bySlug(category, slug),
})

useEffect(() => {
const currentState = history.state
const currentLocation = window.location.href
const nextUrl = new URL(currentLocation)
nextUrl.pathname = `/posts/${category}/${slug}`
const nextUrlString = nextUrl.href

// 虽然但是,这样浏览器的前进后退会有问题
// 如果用 NextJS 的 parallel-routes 情况太复杂
history.replaceState(null, '', nextUrlString)
return () => {
history.replaceState(currentState, '', currentLocation)
}
}, [category, slug])

const overrideAtom = useMemo(() => atom(null! as PostModel), [])
if (isLoading) return <Loading className="w-full" useDefaultLoadingText />
if (!data) return null
Expand Down

1 comment on commit acc815e

@vercel
Copy link

@vercel vercel bot commented on acc815e Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

shiro – ./

shiro-git-main-innei.vercel.app
shiro-innei.vercel.app
innei.in
springtide.vercel.app

Please sign in to comment.