Skip to content

Commit

Permalink
Merge branch 'canary' into update/flakey-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Feb 8, 2022
2 parents 8b9cc24 + 1efa892 commit 4c35ccf
Show file tree
Hide file tree
Showing 22 changed files with 97 additions and 40 deletions.
1 change: 1 addition & 0 deletions docs/authentication.md
Expand Up @@ -134,6 +134,7 @@ To see examples with other authentication providers, check out the [examples fol
<summary><b>Examples</b></summary>
<ul>
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-firebase-authentication">with-firebase-authentication</a></li>
<li><a href="https://github.com/vercel/examples/tree/main/solutions/auth-with-ory">auth-with-ory</a></li>
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-magic">with-magic</a></li>
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/auth0">auth0</a></li>
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/with-supabase-auth-realtime-db">with-supabase-auth-realtime-db</a></li>
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "12.0.11-canary.8"
"version": "12.0.11-canary.9"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "12.0.11-canary.8",
"version": "12.0.11-canary.9",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "12.0.11-canary.8",
"version": "12.0.11-canary.9",
"description": "ESLint configuration used by NextJS.",
"main": "index.js",
"license": "MIT",
Expand All @@ -9,7 +9,7 @@
"directory": "packages/eslint-config-next"
},
"dependencies": {
"@next/eslint-plugin-next": "12.0.11-canary.8",
"@next/eslint-plugin-next": "12.0.11-canary.9",
"@rushstack/eslint-patch": "^1.0.8",
"@typescript-eslint/parser": "^5.0.0",
"eslint-import-resolver-node": "^0.3.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "12.0.11-canary.8",
"version": "12.0.11-canary.9",
"description": "ESLint plugin for NextJS.",
"main": "lib/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "12.0.11-canary.8",
"version": "12.0.11-canary.9",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "12.0.11-canary.8",
"version": "12.0.11-canary.9",
"license": "MIT",
"dependencies": {
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "12.0.11-canary.8",
"version": "12.0.11-canary.9",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "12.0.11-canary.8",
"version": "12.0.11-canary.9",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "12.0.11-canary.8",
"version": "12.0.11-canary.9",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "12.0.11-canary.8",
"version": "12.0.11-canary.9",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "12.0.11-canary.8",
"version": "12.0.11-canary.9",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "12.0.11-canary.8",
"version": "12.0.11-canary.9",
"private": true,
"scripts": {
"build-native": "napi build --platform --cargo-name next_swc_napi native",
Expand Down
1 change: 1 addition & 0 deletions packages/next/build/entries.ts
Expand Up @@ -141,6 +141,7 @@ export function createEntrypoints(
'base64'
),
i18n: config.i18n ? JSON.stringify(config.i18n) : '',
reactRoot: config.experimental.reactRoot ? 'true' : '',
}

Object.keys(pages).forEach((page) => {
Expand Down
Expand Up @@ -31,6 +31,7 @@ export type ServerlessLoaderQuery = {
previewProps: string
loadedEnvFiles: string
i18n: string
reactRoot: string
}

const nextServerlessLoader: webpack.loader.Loader = function () {
Expand All @@ -52,6 +53,7 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
previewProps,
loadedEnvFiles,
i18n,
reactRoot,
}: ServerlessLoaderQuery =
typeof this.query === 'string' ? parse(this.query.substr(1)) : this.query

Expand Down Expand Up @@ -193,6 +195,7 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
canonicalBase: "${canonicalBase}",
generateEtags: ${generateEtags || 'false'},
poweredByHeader: ${poweredByHeader || 'false'},
reactRoot: ${reactRoot || 'false'},
runtimeConfig,
buildManifest,
Expand Down
1 change: 1 addition & 0 deletions packages/next/export/index.ts
Expand Up @@ -386,6 +386,7 @@ export default async function exportApp(
optimizeCss: nextConfig.experimental.optimizeCss,
optimizeFonts: nextConfig.optimizeFonts,
optimizeImages: nextConfig.experimental.optimizeImages,
reactRoot: nextConfig.experimental.reactRoot || false,
}

const { serverRuntimeConfig, publicRuntimeConfig } = nextConfig
Expand Down
14 changes: 7 additions & 7 deletions packages/next/package.json
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "12.0.11-canary.8",
"version": "12.0.11-canary.9",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -69,7 +69,7 @@
]
},
"dependencies": {
"@next/env": "12.0.11-canary.8",
"@next/env": "12.0.11-canary.9",
"caniuse-lite": "^1.0.30001283",
"postcss": "8.4.5",
"styled-jsx": "5.0.0",
Expand Down Expand Up @@ -117,11 +117,11 @@
"@hapi/accept": "5.0.2",
"@napi-rs/cli": "1.2.1",
"@napi-rs/triples": "1.0.3",
"@next/polyfill-module": "12.0.11-canary.8",
"@next/polyfill-nomodule": "12.0.11-canary.8",
"@next/react-dev-overlay": "12.0.11-canary.8",
"@next/react-refresh-utils": "12.0.11-canary.8",
"@next/swc": "12.0.11-canary.8",
"@next/polyfill-module": "12.0.11-canary.9",
"@next/polyfill-nomodule": "12.0.11-canary.9",
"@next/react-dev-overlay": "12.0.11-canary.9",
"@next/react-refresh-utils": "12.0.11-canary.9",
"@next/swc": "12.0.11-canary.9",
"@peculiar/webcrypto": "1.1.7",
"@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/next/server/base-server.ts
Expand Up @@ -163,6 +163,7 @@ export default abstract class Server {
serverComponentManifest?: any
renderServerComponentData?: boolean
serverComponentProps?: any
reactRoot: boolean
}
private incrementalCache: IncrementalCache
private responseCache: ResponseCache
Expand Down Expand Up @@ -321,6 +322,7 @@ export default abstract class Server {
crossOrigin: this.nextConfig.crossOrigin
? this.nextConfig.crossOrigin
: undefined,
reactRoot: this.nextConfig.experimental.reactRoot === true,
}

// Only the `publicRuntimeConfig` key is exposed to the client side
Expand Down
63 changes: 53 additions & 10 deletions packages/next/server/render.tsx
Expand Up @@ -232,6 +232,7 @@ export type RenderOptsPartial = {
serverComponents?: boolean
customServer?: boolean
crossOrigin?: string
reactRoot: boolean
}

export type RenderOpts = LoadComponentsReturnType & RenderOptsPartial
Expand Down Expand Up @@ -456,6 +457,7 @@ export async function renderToHTML(
basePath,
devOnlyCacheBusterQueryString,
supportsDynamicHTML,
reactRoot,
runtime,
} = renderOpts

Expand Down Expand Up @@ -1131,7 +1133,9 @@ export async function renderToHTML(
}),
serverComponentManifest
)
return new RenderResult(stream.pipeThrough(createBufferedTransformStream()))
return new RenderResult(
pipeThrough(stream, createBufferedTransformStream())
)
}

// we preload the buildManifest for auto-export dynamic pages
Expand Down Expand Up @@ -1265,7 +1269,7 @@ export async function renderToHTML(
)
}

if (hasConcurrentFeatures) {
if (reactRoot) {
bodyResult = async (suffix: string) => {
// this must be called inside bodyResult so appWrappers is
// up to date when getWrappedApp is called
Expand All @@ -1277,7 +1281,7 @@ export async function renderToHTML(
suffix,
serverComponentsInlinedTransformStream?.readable ??
streamFromArray([]),
generateStaticHTML
generateStaticHTML || !hasConcurrentFeatures
)
}
} else {
Expand Down Expand Up @@ -1673,16 +1677,18 @@ function renderToStream(
// defer to a microtask to ensure `stream` is set.
Promise.resolve().then(() =>
resolve(
stream
.pipeThrough(createBufferedTransformStream())
.pipeThrough(
pipeThrough(
pipeThrough(
pipeThrough(stream, createBufferedTransformStream()),
createInlineDataStream(
dataStream.pipeThrough(
pipeThrough(
dataStream,
createPrefixStream(suffixState?.suffixUnclosed ?? null)
)
)
)
.pipeThrough(createSuffixStream(suffixState?.closeTag ?? null))
),
createSuffixStream(suffixState?.closeTag ?? null)
)
)
)
}
Expand Down Expand Up @@ -1771,13 +1777,50 @@ function createInlineDataStream(
})
}

function pipeTo(
readable: ReadableStream,
writable: WritableStream,
options?: { preventClose: boolean }
) {
let resolver: () => void
const promise = new Promise<void>((resolve) => (resolver = resolve))

const reader = readable.getReader()
const writer = writable.getWriter()
function process() {
reader.read().then(({ done, value }) => {
if (done) {
if (options?.preventClose) {
writer.releaseLock()
} else {
writer.close()
}
resolver()
} else {
writer.write(value)
process()
}
})
}
process()
return promise
}

function pipeThrough(
readable: ReadableStream,
transformStream: TransformStream
) {
pipeTo(readable, transformStream.writable)
return transformStream.readable
}

function chainStreams(streams: ReadableStream[]): ReadableStream {
const { readable, writable } = new TransformStream()

let promise = Promise.resolve()
for (let i = 0; i < streams.length; ++i) {
promise = promise.then(() =>
streams[i].pipeTo(writable, {
pipeTo(streams[i], writable, {
preventClose: i + 1 < streams.length,
})
)
Expand Down
22 changes: 14 additions & 8 deletions packages/next/server/web-server.ts
Expand Up @@ -150,14 +150,20 @@ export default class NextWebServer extends BaseServer {
): Promise<void> {
// @TODO
const writer = res.transformStream.writable.getWriter()
options.result.pipe({
write: (chunk: Uint8Array) => writer.write(chunk),
end: () => writer.close(),
destroy: (err: Error) => writer.abort(err),
cork: () => {},
uncork: () => {},
// Not implemented: on/removeListener
} as any)

if (options.result.isDynamic()) {
options.result.pipe({
write: (chunk: Uint8Array) => writer.write(chunk),
end: () => writer.close(),
destroy: (err: Error) => writer.abort(err),
cork: () => {},
uncork: () => {},
// Not implemented: on/removeListener
} as any)
} else {
res.body(await options.result.toUnchunkedString())
}

res.send()
}
protected async runApi() {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dev-overlay/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/react-dev-overlay",
"version": "12.0.11-canary.8",
"version": "12.0.11-canary.9",
"description": "A development-only overlay for developing React applications.",
"repository": {
"url": "vercel/next.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-refresh-utils/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/react-refresh-utils",
"version": "12.0.11-canary.8",
"version": "12.0.11-canary.9",
"description": "An experimental package providing utilities for React Refresh.",
"repository": {
"url": "vercel/next.js",
Expand Down

0 comments on commit 4c35ccf

Please sign in to comment.