Skip to content

Commit

Permalink
Merge branch 'canary' into basepath-router-events
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Jul 20, 2020
2 parents 6fa75df + 5a00d62 commit 60a32a9
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 41 deletions.
4 changes: 2 additions & 2 deletions examples/with-sentry/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ process.env.SENTRY_DSN = SENTRY_DSN

module.exports = withSourceMaps({
webpack: (config, options) => {
// In `pages/_app.js`, Sentry is imported from @sentry/node. While
// @sentry/browser will run in a Node.js environment, @sentry/node will use
// In `pages/_app.js`, Sentry is imported from @sentry/browser. While
// @sentry/node will run in a Node.js environment. @sentry/node will use
// Node.js-only APIs to catch even more unhandled exceptions.
//
// This works well when Next.js is SSRing your page on a server with
Expand Down
6 changes: 2 additions & 4 deletions packages/next/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ export const GSSP_NO_RETURNED_VALUE =
'Your `getServerSideProps` function did not return an object. Did you forget to add a `return`?'

export const UNSTABLE_REVALIDATE_RENAME_ERROR =
'The `revalidate` property is not yet available for general use.\n' +
'To try the experimental implementation, please use `unstable_revalidate` instead.\n' +
"We're excited for you to try this feature—please share all feedback on the RFC:\n" +
'https://nextjs.link/issg'
'The `unstable_revalidate` property is available for general use.\n' +
'Please use `revalidate` instead.'

export const GSSP_COMPONENT_MEMBER_ERROR = `can not be attached to a page's component and must be exported from the page. See more info here: https://err.sh/next.js/gssp-component-member`

Expand Down
8 changes: 4 additions & 4 deletions packages/next/lib/load-custom-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,13 @@ export default async function loadCustomRoutes(
if (config.trailingSlash) {
redirects.unshift(
{
source: '/:path*/:file.:ext/',
destination: '/:path*/:file.:ext',
source: '/:file((?:[^/]+/)*[^/]+\\.\\w+)/',
destination: '/:file',
permanent: true,
},
{
source: '/:path*/:notfile([^/.]+)',
destination: '/:path*/:notfile/',
source: '/:notfile((?:[^/]+/)*[^/\\.]+)',
destination: '/:notfile/',
permanent: true,
}
)
Expand Down
24 changes: 12 additions & 12 deletions packages/next/next-server/server/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,10 @@ export async function renderToHTML(
}

const invalidKeys = Object.keys(data).filter(
(key) => key !== 'unstable_revalidate' && key !== 'props'
(key) => key !== 'revalidate' && key !== 'props'
)

if (invalidKeys.includes('revalidate')) {
if (invalidKeys.includes('unstable_revalidate')) {
throw new Error(UNSTABLE_REVALIDATE_RENAME_ERROR)
}

Expand All @@ -546,41 +546,41 @@ export async function renderToHTML(
)
}

if (typeof data.unstable_revalidate === 'number') {
if (!Number.isInteger(data.unstable_revalidate)) {
if (typeof data.revalidate === 'number') {
if (!Number.isInteger(data.revalidate)) {
throw new Error(
`A page's revalidate option must be seconds expressed as a natural number. Mixed numbers, such as '${data.unstable_revalidate}', cannot be used.` +
`A page's revalidate option must be seconds expressed as a natural number. Mixed numbers, such as '${data.revalidate}', cannot be used.` +
`\nTry changing the value to '${Math.ceil(
data.unstable_revalidate
data.revalidate
)}' or using \`Math.ceil()\` if you're computing the value.`
)
} else if (data.unstable_revalidate <= 0) {
} else if (data.revalidate <= 0) {
throw new Error(
`A page's revalidate option can not be less than or equal to zero. A revalidate option of zero means to revalidate after _every_ request, and implies stale data cannot be tolerated.` +
`\n\nTo never revalidate, you can set revalidate to \`false\` (only ran once at build-time).` +
`\nTo revalidate as soon as possible, you can set the value to \`1\`.`
)
} else if (data.unstable_revalidate > 31536000) {
} else if (data.revalidate > 31536000) {
// if it's greater than a year for some reason error
console.warn(
`Warning: A page's revalidate option was set to more than a year. This may have been done in error.` +
`\nTo only run getStaticProps at build-time and not revalidate at runtime, you can set \`revalidate\` to \`false\`!`
)
}
} else if (data.unstable_revalidate === true) {
} else if (data.revalidate === true) {
// When enabled, revalidate after 1 second. This value is optimal for
// the most up-to-date page possible, but without a 1-to-1
// request-refresh ratio.
data.unstable_revalidate = 1
data.revalidate = 1
} else {
// By default, we never revalidate.
data.unstable_revalidate = false
data.revalidate = false
}

props.pageProps = Object.assign({}, props.pageProps, data.props)
// pass up revalidate and props for export
// TODO: change this to a different passing mechanism
;(renderOpts as any).revalidate = data.unstable_revalidate
;(renderOpts as any).revalidate = data.revalidate
;(renderOpts as any).pageData = props
}

Expand Down
2 changes: 1 addition & 1 deletion packages/next/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export type GetStaticPropsContext<Q extends ParsedUrlQuery = ParsedUrlQuery> = {

export type GetStaticPropsResult<P> = {
props: P
unstable_revalidate?: number | boolean
revalidate?: number | boolean
}

export type GetStaticProps<
Expand Down
2 changes: 1 addition & 1 deletion test/integration/env-config/app/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function getStaticProps() {
// Do not pass any sensitive values here as they will
// be made PUBLICLY available in `pageProps`
props: { env: items },
unstable_revalidate: 1,
revalidate: 1,
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/env-config/app/pages/some-ssg.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function getStaticProps() {
// Do not pass any sensitive values here as they will
// be made PUBLICLY available in `pageProps`
props: { env: items },
unstable_revalidate: 1,
revalidate: 1,
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/prerender/pages/another/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function getStaticProps() {
world: text,
time: new Date().getTime(),
},
unstable_revalidate: true,
revalidate: true,
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/prerender/pages/blog/[post]/[comment].js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function getStaticProps({ params }) {
comment: params.comment,
time: new Date().getTime(),
},
unstable_revalidate: 2,
revalidate: 2,
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/prerender/pages/blog/[post]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export async function getStaticProps({ params }) {
post: params.post,
time: (await import('perf_hooks')).performance.now(),
},
unstable_revalidate: 10,
revalidate: 10,
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/prerender/pages/blog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function getStaticProps() {
slugs: ['post-1', 'post-2'],
time: (await import('perf_hooks')).performance.now(),
},
unstable_revalidate: 10,
revalidate: 10,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function getStaticProps({ params: { slug } }) {
props: {
slug,
},
unstable_revalidate: 1,
revalidate: 1,
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/prerender/pages/catchall/[...slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function getStaticProps({ params: { slug } }) {
props: {
slug,
},
unstable_revalidate: 1,
revalidate: 1,
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/prerender/pages/fallback-only/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function getStaticProps({ params }) {
random: Math.random(),
time: (await import('perf_hooks')).performance.now(),
},
unstable_revalidate: 1,
revalidate: 1,
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/prerender/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export async function getStaticProps() {
return {
props: { world: 'world', time: new Date().getTime() },
// bad-prop
unstable_revalidate: 1,
revalidate: 1,
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/prerender/pages/something.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function getStaticProps({ params }) {
time: new Date().getTime(),
random: Math.random(),
},
unstable_revalidate: false,
revalidate: false,
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/prerender/pages/user/[user]/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function getStaticProps({ params }) {
user: params.user,
time: (await import('perf_hooks')).performance.now(),
},
unstable_revalidate: 10,
revalidate: 10,
}
}

Expand Down
8 changes: 4 additions & 4 deletions test/integration/trailing-slashes/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ describe('Trailing slashes', () => {
expect.objectContaining({
redirects: expect.arrayContaining([
expect.objectContaining({
source: '/:path*/:file.:ext/',
destination: '/:path*/:file.:ext',
source: '/:file((?:[^/]+/)*[^/]+\\.\\w+)/',
destination: '/:file',
statusCode: 308,
}),
expect.objectContaining({
source: '/:path*/:notfile([^/.]+)',
destination: '/:path*/:notfile/',
source: '/:notfile((?:[^/]+/)*[^/\\.]+)',
destination: '/:notfile/',
statusCode: 308,
}),
]),
Expand Down
2 changes: 1 addition & 1 deletion test/integration/typescript/pages/ssg/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getStaticProps: GetStaticProps<Props, Params> = async ({
}) => {
return {
props: { data: params!.slug },
unstable_revalidate: false,
revalidate: false,
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/typescript/pages/ssg/blog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { InferGetStaticPropsType } from 'next'
export const getStaticProps = async () => {
return {
props: { data: ['hello', 'world'] },
unstable_revalidate: false,
revalidate: false,
}
}

Expand Down

0 comments on commit 60a32a9

Please sign in to comment.