Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SPR handling with dot in name #9227

Merged
merged 3 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/next/export/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default async function ({
}

const baseDir = join(outDir, dirname(htmlFilename))
const htmlFilepath = join(outDir, htmlFilename)
let htmlFilepath = join(outDir, htmlFilename)

await mkdirp(baseDir)
let html
Expand All @@ -117,6 +117,12 @@ export default async function ({
// prerendered the file
if (renderedDuringBuild(mod.unstable_getStaticProps)) return results

if (mod.unstable_getStaticProps && !htmlFilepath.endsWith('.html')) {
// make sure it ends with .html if the name contains a dot
htmlFilename += '.html'
htmlFilepath += '.html'
}

renderMethod = mod.renderReqToHTML
const result = await renderMethod(req, res, true)
curRenderOpts = result.renderOpts || {}
Expand All @@ -139,6 +145,16 @@ export default async function ({
return results
}

// TODO: de-dupe the logic here between serverless and server mode
if (
components.unstable_getStaticProps &&
!htmlFilepath.endsWith('.html')
) {
// make sure it ends with .html if the name contains a dot
htmlFilepath += '.html'
htmlFilename += '.html'
}

if (typeof components.Component === 'string') {
html = components.Component
} else {
Expand Down
7 changes: 6 additions & 1 deletion test/integration/prerender/pages/blog/[post]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import Link from 'next/link'

// eslint-disable-next-line camelcase
export async function unstable_getStaticParams () {
return ['/blog/post-1', { post: 'post-2' }, '/blog/[post3]']
return [
'/blog/post-1',
{ post: 'post-2' },
'/blog/[post3]',
'/blog/post.1'
]
}

// eslint-disable-next-line camelcase
Expand Down
5 changes: 5 additions & 0 deletions test/integration/prerender/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ const expectedManifestRoutes = () => ({
initialRevalidateSeconds: 2,
srcRoute: '/blog/[post]/[comment]'
},
'/blog/post.1': {
dataRoute: `/_next/data/${buildId}/blog/post.1.json`,
initialRevalidateSeconds: 10,
srcRoute: '/blog/[post]'
},
'/another': {
dataRoute: `/_next/data/${buildId}/another.json`,
initialRevalidateSeconds: 0,
Expand Down