Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
9b8a9dea
Unverified
Commit
9b8a9dea
authored
Apr 26, 2020
by
JJ Kasper
Committed by
GitHub
Apr 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix basePath not being applied for GS(S)P data routes (#12200)
parent
5d8968f6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
74 additions
and
5 deletions
+74
-5
page-loader.js
packages/next/client/page-loader.js
+5
-2
router.ts
packages/next/next-server/lib/router/router.ts
+5
-3
gsp.js
test/integration/basepath/pages/gsp.js
+15
-0
gssp.js
test/integration/basepath/pages/gssp.js
+15
-0
hello.js
test/integration/basepath/pages/hello.js
+12
-0
index.test.js
test/integration/basepath/test/index.test.js
+22
-0
No files found.
packages/next/client/page-loader.js
View file @
9b8a9dea
...
@@ -3,6 +3,7 @@ import mitt from '../next-server/lib/mitt'
...
@@ -3,6 +3,7 @@ import mitt from '../next-server/lib/mitt'
import
{
isDynamicRoute
}
from
'./../next-server/lib/router/utils/is-dynamic'
import
{
isDynamicRoute
}
from
'./../next-server/lib/router/utils/is-dynamic'
import
{
getRouteMatcher
}
from
'./../next-server/lib/router/utils/route-matcher'
import
{
getRouteMatcher
}
from
'./../next-server/lib/router/utils/route-matcher'
import
{
getRouteRegex
}
from
'./../next-server/lib/router/utils/route-regex'
import
{
getRouteRegex
}
from
'./../next-server/lib/router/utils/route-regex'
import
{
delBasePath
}
from
'./../next-server/lib/router/router'
function
hasRel
(
rel
,
link
)
{
function
hasRel
(
rel
,
link
)
{
try
{
try
{
...
@@ -96,10 +97,12 @@ export default class PageLoader {
...
@@ -96,10 +97,12 @@ export default class PageLoader {
* @param {string} asPath the URL as shown in browser (virtual path); used for dynamic routes
* @param {string} asPath the URL as shown in browser (virtual path); used for dynamic routes
*/
*/
getDataHref
(
href
,
asPath
)
{
getDataHref
(
href
,
asPath
)
{
const
getHrefForSlug
=
(
/** @type string */
path
)
=>
const
getHrefForSlug
=
(
/** @type string */
path
)
=>
{
`
${
this
.
assetPrefix
}
/_next/data/
${
this
.
buildId
}${
path
=
delBasePath
(
path
)
return
`
${
this
.
assetPrefix
}
/_next/data/
${
this
.
buildId
}${
path
===
'/'
?
'/index'
:
path
path
===
'/'
?
'/index'
:
path
}
.json`
}
.json`
}
const
{
pathname
:
hrefPathname
,
query
}
=
parse
(
href
,
true
)
const
{
pathname
:
hrefPathname
,
query
}
=
parse
(
href
,
true
)
const
{
pathname
:
asPathname
}
=
parse
(
asPath
)
const
{
pathname
:
asPathname
}
=
parse
(
asPath
)
...
...
packages/next/next-server/lib/router/router.ts
View file @
9b8a9dea
...
@@ -22,7 +22,7 @@ export function addBasePath(path: string): string {
...
@@ -22,7 +22,7 @@ export function addBasePath(path: string): string {
return
path
.
indexOf
(
basePath
)
!==
0
?
basePath
+
path
:
path
return
path
.
indexOf
(
basePath
)
!==
0
?
basePath
+
path
:
path
}
}
function
delBasePath
(
path
:
string
):
string
{
export
function
delBasePath
(
path
:
string
):
string
{
return
path
.
indexOf
(
basePath
)
===
0
return
path
.
indexOf
(
basePath
)
===
0
?
path
.
substr
(
basePath
.
length
)
||
'/'
?
path
.
substr
(
basePath
.
length
)
||
'/'
:
path
:
path
...
@@ -91,8 +91,10 @@ function fetchNextData(
...
@@ -91,8 +91,10 @@ function fetchNextData(
function
getResponse
():
Promise
<
any
>
{
function
getResponse
():
Promise
<
any
>
{
return
fetch
(
return
fetch
(
formatWithValidation
({
formatWithValidation
({
// @ts-ignore __NEXT_DATA__
pathname
:
addBasePath
(
pathname
:
`/_next/data/
${
__NEXT_DATA__
.
buildId
}${
pathname
}
.json`
,
// @ts-ignore __NEXT_DATA__
`/_next/data/
${
__NEXT_DATA__
.
buildId
}${
delBasePath
(
pathname
)}
.json`
),
query
,
query
,
}),
}),
{
{
...
...
test/integration/basepath/pages/gsp.js
0 → 100644
View file @
9b8a9dea
export
const
getStaticProps
=
()
=>
{
return
{
props
:
{
hello
:
'world'
,
random
:
Math
.
random
(),
},
}
}
export
default
props
=>
(
<>
<
h3
id
=
"gsp"
>
getStaticProps
<
/h3
>
<
p
id
=
"props"
>
{
JSON
.
stringify
(
props
)}
<
/p
>
<
/
>
)
test/integration/basepath/pages/gssp.js
0 → 100644
View file @
9b8a9dea
export
const
getServerSideProps
=
()
=>
{
return
{
props
:
{
hello
:
'world'
,
random
:
Math
.
random
(),
},
}
}
export
default
props
=>
(
<>
<
h3
id
=
"gssp"
>
getServerSideProps
<
/h3
>
<
p
id
=
"props"
>
{
JSON
.
stringify
(
props
)}
<
/p
>
<
/
>
)
test/integration/basepath/pages/hello.js
View file @
9b8a9dea
...
@@ -8,6 +8,18 @@ export default () => (
...
@@ -8,6 +8,18 @@ export default () => (
<
h1
>
Hello
World
<
/h1
>
<
h1
>
Hello
World
<
/h1
>
<
/a
>
<
/a
>
<
/Link
>
<
/Link
>
<
br
/>
<
Link
href
=
"/gsp"
>
<
a
id
=
"gsp-link"
>
<
h1
>
getStaticProps
<
/h1
>
<
/a
>
<
/Link
>
<
br
/>
<
Link
href
=
"/gssp"
>
<
a
id
=
"gssp-link"
>
<
h1
>
getServerSideProps
<
/h1
>
<
/a
>
<
/Link
>
<
div
id
=
"base-path"
>
{
useRouter
().
basePath
}
<
/div
>
<
div
id
=
"base-path"
>
{
useRouter
().
basePath
}
<
/div
>
<
/
>
<
/
>
)
)
test/integration/basepath/test/index.test.js
View file @
9b8a9dea
...
@@ -50,6 +50,28 @@ const runTests = (context, dev = false) => {
...
@@ -50,6 +50,28 @@ const runTests = (context, dev = false) => {
}
}
})
})
it
(
'should fetch data for getStaticProps without reloading'
,
async
()
=>
{
const
browser
=
await
webdriver
(
context
.
appPort
,
'/docs/hello'
)
await
browser
.
eval
(
'window.beforeNavigate = true'
)
await
browser
.
elementByCss
(
'#gsp-link'
).
click
()
await
browser
.
waitForElementByCss
(
'#gsp'
)
expect
(
await
browser
.
eval
(
'window.beforeNavigate'
)).
toBe
(
true
)
const
props
=
JSON
.
parse
(
await
browser
.
elementByCss
(
'#props'
).
text
())
expect
(
props
.
hello
).
toBe
(
'world'
)
})
it
(
'should fetch data for getServerSideProps without reloading'
,
async
()
=>
{
const
browser
=
await
webdriver
(
context
.
appPort
,
'/docs/hello'
)
await
browser
.
eval
(
'window.beforeNavigate = true'
)
await
browser
.
elementByCss
(
'#gsp-link'
).
click
()
await
browser
.
waitForElementByCss
(
'#gsp'
)
expect
(
await
browser
.
eval
(
'window.beforeNavigate'
)).
toBe
(
true
)
const
props
=
JSON
.
parse
(
await
browser
.
elementByCss
(
'#props'
).
text
())
expect
(
props
.
hello
).
toBe
(
'world'
)
})
it
(
'should have correct href for a link'
,
async
()
=>
{
it
(
'should have correct href for a link'
,
async
()
=>
{
const
browser
=
await
webdriver
(
context
.
appPort
,
'/docs/hello'
)
const
browser
=
await
webdriver
(
context
.
appPort
,
'/docs/hello'
)
const
href
=
await
browser
.
elementByCss
(
'a'
).
getAttribute
(
'href'
)
const
href
=
await
browser
.
elementByCss
(
'a'
).
getAttribute
(
'href'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment