Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CoCo_Code_Op2
next.js
提交
c8b51b5c
N
next.js
项目概览
CoCo_Code_Op2
/
next.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
next.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c8b51b5c
编写于
6月 11, 2020
作者:
J
Joe Haddad
提交者:
GitHub
6月 11, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "Add scroll restoration handling after render is done" (#14075)
上级
3d6d033a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
0 addition
and
185 deletion
+0
-185
packages/next/next-server/lib/router/router.ts
packages/next/next-server/lib/router/router.ts
+0
-28
test/integration/scroll-restoration/pages/another.js
test/integration/scroll-restoration/pages/another.js
+0
-1
test/integration/scroll-restoration/pages/index.js
test/integration/scroll-restoration/pages/index.js
+0
-50
test/integration/scroll-restoration/test/index.test.js
test/integration/scroll-restoration/test/index.test.js
+0
-106
未找到文件。
packages/next/next-server/lib/router/router.ts
浏览文件 @
c8b51b5c
...
...
@@ -94,9 +94,6 @@ type ComponentLoadCancel = (() => void) | null
type
HistoryMethod
=
'
replaceState
'
|
'
pushState
'
const
manualScrollRestoration
=
typeof
window
!==
'
undefined
'
&&
'
scrollRestoration
'
in
window
.
history
function
fetchNextData
(
pathname
:
string
,
query
:
ParsedUrlQuery
|
null
,
...
...
@@ -259,12 +256,6 @@ export default class Router implements BaseRouter {
}
window
.
addEventListener
(
'
popstate
'
,
this
.
onPopState
)
// enable custom scroll restoration handling when available
// otherwise fallback to browser's default handling
if
(
manualScrollRestoration
)
{
window
.
history
.
scrollRestoration
=
'
manual
'
}
}
}
...
...
@@ -502,21 +493,6 @@ export default class Router implements BaseRouter {
}
Router
.
events
.
emit
(
'
beforeHistoryChange
'
,
as
)
if
(
manualScrollRestoration
&&
history
.
state
)
{
const
{
url
:
curUrl
,
as
:
curAs
,
options
:
curOptions
,
}
=
history
.
state
this
.
changeState
(
'
replaceState
'
,
curUrl
,
curAs
,
{
...
curOptions
,
_N_X
:
window
.
scrollX
,
_N_Y
:
window
.
scrollY
,
})
}
this
.
changeState
(
method
,
url
,
as
,
options
)
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
...
...
@@ -534,10 +510,6 @@ export default class Router implements BaseRouter {
}
Router
.
events
.
emit
(
'
routeChangeComplete
'
,
as
)
if
(
manualScrollRestoration
&&
'
_N_X
'
in
options
)
{
window
.
scrollTo
(
options
.
_N_X
,
options
.
_N_Y
)
}
return
resolve
(
true
)
}
)
...
...
test/integration/scroll-restoration/pages/another.js
已删除
100644 → 0
浏览文件 @
3d6d033a
export
default
()
=>
<
p
id
=
"
another
"
>
hi
from
another
<
/p
>
test/integration/scroll-restoration/pages/index.js
已删除
100644 → 0
浏览文件 @
3d6d033a
import
Link
from
'
next/link
'
const
Page
=
({
loaded
})
=>
{
const
link
=
(
<
Link
href
=
"
/another
"
>
<
a
id
=
"
to-another
"
style
=
{{
marginLeft
:
5000
,
width
:
95000
,
display
:
'
block
'
,
}}
>
to
another
<
/a
>
<
/Link
>
)
if
(
typeof
window
!==
'
undefined
'
)
{
window
.
didHydrate
=
true
}
if
(
loaded
)
{
return
(
<>
<
div
style
=
{{
width
:
10000
,
height
:
10000
,
background
:
'
orange
'
,
}}
/
>
{
link
}
<
div
id
=
"
end-el
"
>
the
end
<
/div
>
<
/
>
)
}
return
link
}
export
default
Page
export
const
getServerSideProps
=
()
=>
{
return
{
props
:
{
loaded
:
true
,
},
}
}
test/integration/scroll-restoration/test/index.test.js
已删除
100644 → 0
浏览文件 @
3d6d033a
/* eslint-env jest */
import
fs
from
'
fs-extra
'
import
{
join
}
from
'
path
'
import
webdriver
from
'
next-webdriver
'
import
{
killApp
,
findPort
,
launchApp
,
nextStart
,
nextBuild
,
check
,
}
from
'
next-test-utils
'
jest
.
setTimeout
(
1000
*
60
*
2
)
const
appDir
=
join
(
__dirname
,
'
../
'
)
const
nextConfig
=
join
(
appDir
,
'
next.config.js
'
)
let
appPort
let
app
const
runTests
=
()
=>
{
it
(
'
should restore the scroll position on navigating back
'
,
async
()
=>
{
const
browser
=
await
webdriver
(
appPort
,
'
/
'
)
await
browser
.
eval
(()
=>
document
.
querySelector
(
'
#to-another
'
).
scrollIntoView
()
)
const
scrollRestoration
=
await
browser
.
eval
(
()
=>
window
.
history
.
scrollRestoration
)
expect
(
scrollRestoration
).
toBe
(
'
manual
'
)
const
scrollX
=
Math
.
floor
(
await
browser
.
eval
(()
=>
window
.
scrollX
))
const
scrollY
=
Math
.
floor
(
await
browser
.
eval
(()
=>
window
.
scrollY
))
expect
(
scrollX
).
not
.
toBe
(
0
)
expect
(
scrollY
).
not
.
toBe
(
0
)
await
browser
.
eval
(()
=>
window
.
next
.
router
.
push
(
'
/another
'
))
await
check
(
()
=>
browser
.
eval
(()
=>
document
.
documentElement
.
innerHTML
),
/hi from another/
)
await
browser
.
eval
(()
=>
(
window
.
didHydrate
=
false
))
await
browser
.
eval
(()
=>
window
.
history
.
back
())
await
check
(()
=>
browser
.
eval
(()
=>
window
.
didHydrate
),
{
test
(
content
)
{
return
content
},
})
const
newScrollX
=
Math
.
floor
(
await
browser
.
eval
(()
=>
window
.
scrollX
))
const
newScrollY
=
Math
.
floor
(
await
browser
.
eval
(()
=>
window
.
scrollY
))
expect
(
scrollX
).
toBe
(
newScrollX
)
expect
(
scrollY
).
toBe
(
newScrollY
)
})
}
describe
(
'
Scroll Restoration Support
'
,
()
=>
{
describe
(
'
dev mode
'
,
()
=>
{
beforeAll
(
async
()
=>
{
appPort
=
await
findPort
()
app
=
await
launchApp
(
appDir
,
appPort
)
})
afterAll
(()
=>
killApp
(
app
))
runTests
()
})
describe
(
'
server mode
'
,
()
=>
{
beforeAll
(
async
()
=>
{
await
nextBuild
(
appDir
)
appPort
=
await
findPort
()
app
=
await
nextStart
(
appDir
,
appPort
)
})
afterAll
(()
=>
killApp
(
app
))
runTests
()
})
describe
(
'
serverless mode
'
,
()
=>
{
beforeAll
(
async
()
=>
{
await
fs
.
writeFile
(
nextConfig
,
`
module.exports = {
target: 'experimental-serverless-trace'
}
`
)
await
nextBuild
(
appDir
)
appPort
=
await
findPort
()
app
=
await
nextStart
(
appDir
,
appPort
)
})
afterAll
(
async
()
=>
{
await
fs
.
remove
(
nextConfig
)
await
killApp
(
app
)
})
runTests
()
})
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录