Skip to content

Commit

Permalink
Make sure to handle paths with dot in name for SPR (#9227)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk authored Oct 30, 2019
1 parent 8dd394a commit f16f868
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
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

0 comments on commit f16f868

Please sign in to comment.