Skip to content

Commit

Permalink
Merge branch 'canary' into support_cacheStrategy_eslint_arg
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle authored Nov 6, 2021
2 parents b3b75e1 + f8e6661 commit 12baf74
Show file tree
Hide file tree
Showing 25 changed files with 206 additions and 168 deletions.
4 changes: 2 additions & 2 deletions examples/cms-strapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"remark": "12.0.0",
"remark-html": "11.0.2"
"remark": "^14.0.1",
"remark-html": "^15.0.0"
},
"devDependencies": {
"autoprefixer": "10.2.6",
Expand Down
15 changes: 15 additions & 0 deletions examples/with-supertokens/config/appInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const port = process.env.APP_PORT || 3000

const apiBasePath = '/api/auth/'

export const websiteDomain =
process.env.APP_URL ||
process.env.NEXT_PUBLIC_APP_URL ||
`http://localhost:${port}`

export const appInfo = {
appName: 'SuperTokens Demo App',
websiteDomain,
apiDomain: websiteDomain,
apiBasePath,
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import ThirdPartyEmailPasswordNode from 'supertokens-node/recipe/thirdpartyemailpassword'
import SessionNode from 'supertokens-node/recipe/session'

import ThirdPartyEmailPasswordReact from 'supertokens-auth-react/recipe/thirdpartyemailpassword'
import SessionReact from 'supertokens-auth-react/recipe/session'

const port = process.env.APP_PORT || 3000
const websiteDomain =
process.env.APP_URL ||
process.env.NEXT_PUBLIC_APP_URL ||
`http://localhost:${port}`
const apiBasePath = '/api/auth/'

let appInfo = {
appName: 'SuperTokens Demo App',
websiteDomain,
apiDomain: websiteDomain,
apiBasePath,
}
import { appInfo } from './appInfo'

export let backendConfig = () => {
return {
Expand Down Expand Up @@ -50,23 +34,3 @@ export let backendConfig = () => {
isInServerlessEnv: true,
}
}

export let frontendConfig = () => {
return {
appInfo,
recipeList: [
ThirdPartyEmailPasswordReact.init({
emailVerificationFeature: {
mode: 'REQUIRED',
},
signInAndUpFeature: {
providers: [
ThirdPartyEmailPasswordReact.Google.init(),
ThirdPartyEmailPasswordReact.Github.init(),
],
},
}),
SessionReact.init(),
],
}
}
23 changes: 23 additions & 0 deletions examples/with-supertokens/config/frontendConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import ThirdPartyEmailPasswordReact from 'supertokens-auth-react/recipe/thirdpartyemailpassword'
import SessionReact from 'supertokens-auth-react/recipe/session'
import { appInfo } from './appInfo'

export let frontendConfig = () => {
return {
appInfo,
recipeList: [
ThirdPartyEmailPasswordReact.init({
emailVerificationFeature: {
mode: 'REQUIRED',
},
signInAndUpFeature: {
providers: [
ThirdPartyEmailPasswordReact.Google.init(),
ThirdPartyEmailPasswordReact.Github.init(),
],
},
}),
SessionReact.init(),
],
}
}
11 changes: 8 additions & 3 deletions examples/with-supertokens/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ import '../styles/globals.css'
import React from 'react'
import { useEffect } from 'react'
import SuperTokensReact from 'supertokens-auth-react'
import * as SuperTokensConfig from '../config/supertokensConfig'
import * as SuperTokensConfig from '../config/frontendConfig'
import Session from 'supertokens-auth-react/recipe/session'
import SuperTokensNode from 'supertokens-node'
import { redirectToAuth } from 'supertokens-auth-react/recipe/thirdpartyemailpassword'

async function initNode() {
const supertokensNode = await import('supertokens-node')
const { backendConfig } = await import('../config/backendConfig')
supertokensNode.init(backendConfig())
}

if (typeof window !== 'undefined') {
SuperTokensReact.init(SuperTokensConfig.frontendConfig())
} else {
SuperTokensNode.init(SuperTokensConfig.backendConfig())
initNode().catch(console.error)
}

function MyApp({ Component, pageProps }) {
Expand Down
4 changes: 2 additions & 2 deletions examples/with-supertokens/pages/api/auth/[[...path]].js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import { superTokensNextWrapper } from 'supertokens-node/nextjs'
import supertokens from 'supertokens-node'
import { middleware } from 'supertokens-node/framework/express'
import * as SuperTokensConfig from '../../../config/supertokensConfig'
import { backendConfig } from '../../../config/backendConfig'

supertokens.init(SuperTokensConfig.backendConfig())
supertokens.init(backendConfig())

export default async function superTokens(req, res) {
await superTokensNextWrapper(
Expand Down
4 changes: 2 additions & 2 deletions examples/with-supertokens/pages/api/user.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { superTokensNextWrapper } from 'supertokens-node/nextjs'
import { verifySession } from 'supertokens-node/recipe/session/framework/express'
import supertokens from 'supertokens-node'
import * as SuperTokensConfig from '../../config/supertokensConfig'
import { backendConfig } from '../../config/backendConfig'

supertokens.init(SuperTokensConfig.backendConfig())
supertokens.init(backendConfig())

export default async function user(req, res) {
await superTokensNextWrapper(
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@
"pretty-ms": "7.0.0",
"random-seed": "0.3.0",
"react": "17.0.2",
"react-18": "npm:[email protected]3c4c1c470-20211021",
"react-18": "npm:[email protected]13455d26d-20211104",
"react-dom": "17.0.2",
"react-dom-18": "npm:[email protected]3c4c1c470-20211021",
"react-dom-18": "npm:[email protected]13455d26d-20211104",
"react-ssr-prepass": "1.0.8",
"release": "6.3.0",
"request-promise-core": "1.1.2",
Expand Down
18 changes: 6 additions & 12 deletions packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ClientPagesLoaderOptions } from './webpack/loaders/next-client-pages-lo
import { ServerlessLoaderQuery } from './webpack/loaders/next-serverless-loader'
import { LoadedEnvFiles } from '@next/env'
import { NextConfigComplete } from '../server/config-shared'
import { isFlightPage } from './utils'
import { isCustomErrorPage, isFlightPage, isReservedPage } from './utils'
import { ssrEntries } from './webpack/plugins/middleware-plugin'
import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
import { MIDDLEWARE_SSR_RUNTIME_WEBPACK } from '../shared/lib/constants'
Expand Down Expand Up @@ -136,7 +136,10 @@ export function createEntrypoints(
const serverBundlePath = posix.join('pages', bundleFile)

const isLikeServerless = isTargetLikeServerless(target)
const isReserved = isReservedPage(page)
const isCustomError = isCustomErrorPage(page)
const isFlight = isFlightPage(config, absolutePagePath)

const webServerRuntime = !!config.experimental.concurrentFeatures

if (page.match(MIDDLEWARE_ROUTE)) {
Expand All @@ -151,11 +154,7 @@ export function createEntrypoints(
return
}

if (
webServerRuntime &&
!(page === '/_app' || page === '/_error' || page === '/_document') &&
!isApiRoute
) {
if (webServerRuntime && !isReserved && !isCustomError && !isApiRoute) {
ssrEntries.set(clientBundlePath, { requireFlightManifest: isFlight })
serverWeb[serverBundlePath] = finalizeEntrypoint({
name: '[name].js',
Expand Down Expand Up @@ -184,12 +183,7 @@ export function createEntrypoints(
serverlessLoaderOptions
)}!`
} else if (isApiRoute || target === 'server') {
if (
!webServerRuntime ||
page === '/_document' ||
page === '/_app' ||
page === '/_error'
) {
if (!webServerRuntime || isReserved || isCustomError) {
server[serverBundlePath] = [absolutePagePath]
}
} else if (
Expand Down
20 changes: 13 additions & 7 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ import {
printTreeView,
getCssFilePaths,
getUnresolvedModuleFromError,
isReservedPage,
isCustomErrorPage,
} from './utils'
import getBaseWebpackConfig from './webpack-config'
import { PagesManifest } from './webpack/plugins/pages-manifest-plugin'
Expand All @@ -102,8 +104,6 @@ import { TelemetryPlugin } from './webpack/plugins/telemetry-plugin'
import { MiddlewareManifest } from './webpack/plugins/middleware-plugin'
import type { webpack5 as webpack } from 'next/dist/compiled/webpack/webpack'

const RESERVED_PAGE = /^\/(_app|_error|_document|api(\/|$))/

export type SsgRoute = {
initialRevalidateSeconds: number | false
srcRoute: string | null
Expand Down Expand Up @@ -465,7 +465,7 @@ export default async function build(
(page) =>
!isDynamicRoute(page) &&
!page.match(MIDDLEWARE_ROUTE) &&
!page.match(RESERVED_PAGE)
!isReservedPage(page)
)
.map(pageToRoute),
dataRoutes: [],
Expand Down Expand Up @@ -916,7 +916,7 @@ export default async function build(

if (
!isMiddlewareRoute &&
!page.match(RESERVED_PAGE) &&
!isReservedPage(page) &&
!hasConcurrentFeatures
) {
try {
Expand Down Expand Up @@ -1029,7 +1029,8 @@ export default async function build(
isWebSsr:
hasConcurrentFeatures &&
!isMiddlewareRoute &&
!page.match(RESERVED_PAGE),
!isReservedPage(page) &&
!isCustomErrorPage(page),
isHybridAmp,
ssgPageRoutes,
initialRevalidateSeconds: false,
Expand Down Expand Up @@ -1318,7 +1319,9 @@ export default async function build(
// Since custom _app.js can wrap the 404 page we have to opt-out of static optimization if it has getInitialProps
// Only export the static 404 when there is no /_error present
const useStatic404 =
!customAppGetInitialProps && (!hasNonStaticErrorPage || hasPages404)
!hasConcurrentFeatures &&
!customAppGetInitialProps &&
(!hasNonStaticErrorPage || hasPages404)

if (invalidPages.size > 0) {
const err = new Error(
Expand Down Expand Up @@ -1383,7 +1386,10 @@ export default async function build(

const combinedPages = [...staticPages, ...ssgPages]

if (combinedPages.length > 0 || useStatic404 || useDefaultStatic500) {
if (
!hasConcurrentFeatures &&
(combinedPages.length > 0 || useStatic404 || useDefaultStatic500)
) {
const staticGenerationSpan = nextBuildSpan.traceChild('static-generation')
await staticGenerationSpan.traceAsyncFn(async () => {
detectConflictingPaths(
Expand Down
9 changes: 9 additions & 0 deletions packages/next/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { NextConfigComplete } from '../server/config-shared'
import isError from '../lib/is-error'

const { builtinModules } = require('module')
const RESERVED_PAGE = /^\/(_app|_error|_document|api(\/|$))/
const fileGzipStats: { [k: string]: Promise<number> | undefined } = {}
const fsStatGzip = (file: string) => {
const cached = fileGzipStats[file]
Expand Down Expand Up @@ -1144,3 +1145,11 @@ export function getUnresolvedModuleFromError(
const [, moduleName] = error.match(moduleErrorRegex) || []
return builtinModules.find((item: string) => item === moduleName)
}

export function isReservedPage(page: string) {
return RESERVED_PAGE.test(page)
}

export function isCustomErrorPage(page: string) {
return page === '/404' || page === '/500'
}
2 changes: 1 addition & 1 deletion packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export default async function getBaseWebpackConfig(
let useSWCLoader = !babelConfigFile

if (!loggedSwcDisabled && !useSWCLoader && babelConfigFile) {
Log.warn(
Log.info(
`Disabled SWC as replacement for Babel because of custom Babel configuration "${path.relative(
dir,
babelConfigFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ export default async function middlewareRSCLoader(this: any) {
createElement(FlightWrapper, props)
)
}`
: `
const Component = Page`
: `const Component = Page`
}
async function render(request) {
const url = request.nextUrl
const query = Object.fromEntries(url.searchParams)
const { pathname, searchParams } = url
const query = Object.fromEntries(searchParams)
// Preflight request
if (request.method === 'HEAD') {
Expand All @@ -122,9 +122,9 @@ export default async function middlewareRSCLoader(this: any) {
wrapReadable(
renderFlight({
router: {
route: url.pathname,
asPath: url.pathname,
pathname: url.pathname,
route: pathname,
asPath: pathname,
pathname: pathname,
query,
}
})
Expand Down Expand Up @@ -165,9 +165,9 @@ export default async function middlewareRSCLoader(this: any) {
try {
const result = await renderToHTML(
{ url: url.pathname },
{ url: pathname },
{},
url.pathname,
pathname,
query,
renderOpts
)
Expand All @@ -177,7 +177,7 @@ export default async function middlewareRSCLoader(this: any) {
})
} catch (err) {
return new Response(
(err || 'An error occurred while rendering ' + url.pathname + '.').toString(),
(err || 'An error occurred while rendering ' + pathname + '.').toString(),
{
status: 500,
headers: { 'x-middleware-ssr': '1' }
Expand Down
5 changes: 2 additions & 3 deletions packages/next/build/webpack/plugins/middleware-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ export default class MiddlewarePlugin {
)
middlewareManifest.clientInfo = middlewareManifest.sortedMiddleware.map(
(key) => {
const ssrEntryInfo = ssrEntries.get(
middlewareManifest.middleware[key].name
)
const middleware = middlewareManifest.middleware[key]
const ssrEntryInfo = ssrEntries.get(middleware.name)
return [key, !!ssrEntryInfo]
}
)
Expand Down
Loading

0 comments on commit 12baf74

Please sign in to comment.