Skip to content

Commit

Permalink
Add support for app global and segment 404 pages (#49085)
Browse files Browse the repository at this point in the history
See vercel/turbo#4776

This adds support for:

* Default and custom global app 404 pages (`app/not-found`).
* Segment-level 404 pages (`app/segment/not-found`).

This also updates Turbopack:

* vercel/turbo#4787 <!-- Tobias Koppers -
Bugfixes for free var and binding replacement -->
* vercel/turbo#4789 <!-- Alex Kirszenberg -
Print a warning when importing Sass files -->
* vercel/turbo#4776 <!-- Alex Kirszenberg -
Leave pathname formatting up to the caller -->
* vercel/turbo#4790 <!-- Tobias Koppers - remove
inital compilation message by default -->

## TODO:

- [ ] ~~The dev overlay shows up when `notFound()` is called, it should
be hidden~~ (moved to WEB-980)
- [ ] ~~Navigating to the global 404 page doesn't work~~ (this is a bug
in Next.js, see NEXT-963)
- [x] Tests.

---------

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
  • Loading branch information
alexkirsz and sokra committed May 3, 2023
1 parent 1905d14 commit 7092266
Show file tree
Hide file tree
Showing 75 changed files with 809 additions and 546 deletions.
68 changes: 34 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ swc_relay = { version = "0.2.7" }
testing = { version = "0.33.6" }

# Turbo crates
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230502.4" }
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230503.2" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230502.4" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230503.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230502.4" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230503.2" }

# General Deps

Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/next-core/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"check": "tsc --noEmit"
},
"dependencies": {
"@vercel/turbopack-dev": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230502.4",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230502.4",
"@vercel/turbopack-dev": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230503.2",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230503.2",
"anser": "^2.1.1",
"css.escape": "^1.5.1",
"next": "*",
Expand Down
13 changes: 7 additions & 6 deletions packages/next-swc/crates/next-core/js/src/entry/app-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ declare global {
}

import type { Ipc } from '@vercel/turbopack-node/ipc/index'
import type { IncomingMessage, ServerResponse } from 'node:http'
import type { IncomingMessage } from 'node:http'
import type {
ClientCSSReferenceManifest,
ClientReferenceManifest,
Expand All @@ -25,13 +25,13 @@ import type { RenderOpts } from 'next/dist/server/app-render/types'

import { renderToHTMLOrFlight } from 'next/dist/server/app-render/app-render'
import { RSC_VARY_HEADER } from 'next/dist/client/components/app-router-headers'
import { ServerResponseShim } from '../internal/http'
import { headersFromEntries } from '../internal/headers'
import { parse, ParsedUrlQuery } from 'node:querystring'
import { PassThrough } from 'node:stream'
;('TURBOPACK { transition: next-layout-entry; chunking-type: isolatedParallel }')
// @ts-ignore
import layoutEntry from './app/layout-entry'
import { createServerResponse } from '../internal/http'

globalThis.__next_require__ = (data) => {
const [, , ssr_id] = JSON.parse(data)
Expand Down Expand Up @@ -91,7 +91,7 @@ const MIME_TEXT_HTML_UTF8 = 'text/html; charset=utf-8'
ipc.send({
type: 'headers',
data: {
status: 200,
status: result.statusCode,
headers: result.headers,
},
})
Expand Down Expand Up @@ -124,8 +124,6 @@ type LoaderTree = [
]

async function runOperation(renderData: RenderData) {
let tree: LoaderTree = LOADER_TREE

const proxyMethodsForModule = (
id: string
): ProxyHandler<ClientReferenceManifest['ssrModuleMapping']> => {
Expand Down Expand Up @@ -251,7 +249,9 @@ async function runOperation(renderData: RenderData) {
method: renderData.method,
headers: headersFromEntries(renderData.rawHeaders),
} as any
const res: ServerResponse = new ServerResponseShim(req) as any

const res = createServerResponse(req, renderData.path)

const query = parse(renderData.rawQuery)
const renderOpt: Omit<
RenderOpts,
Expand Down Expand Up @@ -304,6 +304,7 @@ async function runOperation(renderData: RenderData) {
body.write(result.toUnchunkedString())
}
return {
statusCode: res.statusCode,
headers: [
['Content-Type', result.contentType() ?? MIME_TEXT_HTML_UTF8],
['Vary', RSC_VARY_HEADER],
Expand Down

0 comments on commit 7092266

Please sign in to comment.