Skip to content

Commit

Permalink
Merge branch 'canary' into fix-redirect-type
Browse files Browse the repository at this point in the history
  • Loading branch information
abhi12299 authored Sep 20, 2024
2 parents 5d141a6 + 1bfac33 commit 3bba5ce
Show file tree
Hide file tree
Showing 10 changed files with 725 additions and 859 deletions.
440 changes: 0 additions & 440 deletions crates/napi/src/app_structure.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ use swc_core::{
common::{FilePathMapping, SourceMap},
};

#[cfg(not(target_arch = "wasm32"))]
pub mod app_structure;
#[cfg(not(target_arch = "wasm32"))]
pub mod css;
pub mod mdx;
Expand Down
65 changes: 0 additions & 65 deletions packages/next/src/build/swc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
type DefineEnvPluginOptions,
getDefineEnv,
} from '../webpack/plugins/define-env-plugin'
import type { PageExtensions } from '../page-extensions-type'
import type { __ApiPreviewProps } from '../../server/api-utils'
import { getReactCompilerLoader } from '../get-babel-loader-config'
import { TurbopackInternalError } from '../../server/dev/turbopack-utils'
Expand Down Expand Up @@ -158,10 +157,6 @@ export interface Binding {
startTrace: any
nextBuild?: any
createTurboTasks?: any
entrypoints: {
stream: any
get: any
}
createProject: (
options: ProjectOptions,
turboEngineOptions?: TurboEngineOptions
Expand Down Expand Up @@ -1377,36 +1372,6 @@ async function loadWasm(importPath = '') {
startTrace: () => {
Log.error('Wasm binding does not support trace yet')
},
entrypoints: {
stream: (
turboTasks: any,
rootDir: string,
applicationDir: string,
pageExtensions: PageExtensions,
callbackFn: (err: Error, entrypoints: any) => void
) => {
return bindings.streamEntrypoints(
turboTasks,
rootDir,
applicationDir,
pageExtensions,
callbackFn
)
},
get: (
turboTasks: any,
rootDir: string,
applicationDir: string,
pageExtensions: PageExtensions
) => {
return bindings.getEntrypoints(
turboTasks,
rootDir,
applicationDir,
pageExtensions
)
},
},
},
mdx: {
compile: (src: string, options: any) =>
Expand Down Expand Up @@ -1568,36 +1533,6 @@ function loadNative(importPath?: string) {
},
createTurboTasks: (memoryLimit?: number): unknown =>
bindings.createTurboTasks(memoryLimit),
entrypoints: {
stream: (
turboTasks: any,
rootDir: string,
applicationDir: string,
pageExtensions: PageExtensions,
fn: (entrypoints: any) => void
) => {
return (customBindings ?? bindings).streamEntrypoints(
turboTasks,
rootDir,
applicationDir,
pageExtensions,
fn
)
},
get: (
turboTasks: any,
rootDir: string,
applicationDir: string,
pageExtensions: PageExtensions
) => {
return (customBindings ?? bindings).getEntrypoints(
turboTasks,
rootDir,
applicationDir,
pageExtensions
)
},
},
createProject: bindingToApi(customBindings ?? bindings, false),
startTurbopackTraceServer: (traceFilePath) => {
Log.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
getModuleReferencesInOrder,
} from '../utils'
import type { ChunkGroup } from 'webpack'
import { encodeURIPath } from '../../../shared/lib/encode-uri-path'

interface Options {
dev: boolean
Expand Down Expand Up @@ -117,7 +118,10 @@ function getAppPathRequiredChunks(
// previously done for dynamic chunks by patching the webpack runtime but we want
// these filenames to be managed by React's Flight runtime instead and so we need
// to implement any special handling of the file name here.
return chunks.push(chunkId, encodeURI(file + deploymentIdChunkQuery))
return chunks.push(
chunkId,
encodeURIPath(file) + deploymentIdChunkQuery
)
})
}
})
Expand All @@ -143,7 +147,7 @@ function entryNameToGroupName(entryName: string) {
// Remove catch-all routes since they should be part of the parent group that the catch-all would apply to.
// This is necessary to support parallel routes since multiple page components can be rendered on the same page.
// In order to do that, we need to ensure that the manifests are merged together by putting them in the same group.
.replace(/\/\[?\[\.\.\.[^\]]*\]\]?/g, '')
.replace(/\/\[?\[\.\.\.[^\]]*]]?/g, '')

// Interception routes
groupName = groupName
Expand Down
9 changes: 5 additions & 4 deletions packages/next/src/client/app-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// https://github.com/webpack/webpack/blob/2738eebc7880835d88c727d364ad37f3ec557593/lib/RuntimeGlobals.js#L204

import { getDeploymentIdQueryOrEmptyString } from '../build/deployment-id'
import { encodeURIPath } from '../shared/lib/encode-uri-path'

declare const __webpack_require__: any

Expand All @@ -13,9 +14,9 @@ if (process.env.NEXT_DEPLOYMENT_ID) {
const getChunkScriptFilename = __webpack_require__.u
// eslint-disable-next-line no-undef
__webpack_require__.u = (...args: any[]) =>
// We enode the chunk filename because our static server matches against and encoded
// We encode the chunk filename because our static server matches against and encoded
// filename path.
encodeURI(getChunkScriptFilename(...args) + suffix)
encodeURIPath(getChunkScriptFilename(...args)) + suffix

// eslint-disable-next-line no-undef
const getChunkCssFilename = __webpack_require__.k
Expand All @@ -33,9 +34,9 @@ if (process.env.NEXT_DEPLOYMENT_ID) {
const getChunkScriptFilename = __webpack_require__.u
// eslint-disable-next-line no-undef
__webpack_require__.u = (...args: any[]) =>
// We enode the chunk filename because our static server matches against and encoded
// We encode the chunk filename because our static server matches against and encoded
// filename path.
encodeURI(getChunkScriptFilename(...args))
encodeURIPath(getChunkScriptFilename(...args))

// We don't need to override __webpack_require__.k because we don't modify
// the css chunk name when not using deployment id suffixes
Expand Down
13 changes: 8 additions & 5 deletions packages/next/src/client/route-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import getAssetPathFromRoute from '../shared/lib/router/utils/get-asset-path-fro
import { __unsafeCreateTrustedScriptURL } from './trusted-types'
import { requestIdleCallback } from './request-idle-callback'
import { getDeploymentIdQueryOrEmptyString } from '../build/deployment-id'
import { encodeURIPath } from '../shared/lib/encode-uri-path'

// 3.8s was arbitrarily chosen as it's what https://web.dev/interactive
// considers as "Good" time-to-interactive. We must assume something went
Expand Down Expand Up @@ -68,11 +69,13 @@ function withFuture<T extends object>(
const prom: Promise<T> = new Promise<T>((resolve) => {
resolver = resolve
})
map.set(key, (entry = { resolve: resolver!, future: prom }))
map.set(key, { resolve: resolver!, future: prom })
return generator
? generator()
// eslint-disable-next-line no-sequences
.then((value) => (resolver(value), value))
.then((value) => {
resolver(value)
return value
})
.catch((err) => {
map.delete(key)
throw err
Expand Down Expand Up @@ -257,7 +260,7 @@ function getFilesForRoute(
const scriptUrl =
assetPrefix +
'/_next/static/chunks/pages' +
encodeURI(getAssetPathFromRoute(route, '.js')) +
encodeURIPath(getAssetPathFromRoute(route, '.js')) +
getAssetQueryString()
return Promise.resolve({
scripts: [__unsafeCreateTrustedScriptURL(scriptUrl)],
Expand All @@ -270,7 +273,7 @@ function getFilesForRoute(
throw markAssetError(new Error(`Failed to lookup route: ${route}`))
}
const allFiles = manifest[route].map(
(entry) => assetPrefix + '/_next/' + encodeURI(entry)
(entry) => assetPrefix + '/_next/' + encodeURIPath(entry)
)
return {
scripts: allFiles
Expand Down
12 changes: 8 additions & 4 deletions packages/next/src/server/lib/router-utils/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { normalizeMetadataRoute } from '../../../lib/metadata/get-metadata-route
import { RSCPathnameNormalizer } from '../../normalizers/request/rsc'
import { PostponedPathnameNormalizer } from '../../normalizers/request/postponed'
import { PrefetchRSCPathnameNormalizer } from '../../normalizers/request/prefetch-rsc'
import { encodeURIPath } from '../../../shared/lib/encode-uri-path'

export type FsOutput = {
type:
Expand Down Expand Up @@ -162,7 +163,7 @@ export async function setupFsCheck(opts: {
try {
for (const file of await recursiveReadDir(publicFolderPath)) {
// Ensure filename is encoded and normalized.
publicFolderItems.add(encodeURI(normalizePathSep(file)))
publicFolderItems.add(encodeURIPath(normalizePathSep(file)))
}
} catch (err: any) {
if (err.code !== 'ENOENT') {
Expand All @@ -173,7 +174,7 @@ export async function setupFsCheck(opts: {
try {
for (const file of await recursiveReadDir(legacyStaticFolderPath)) {
// Ensure filename is encoded and normalized.
legacyStaticFolderItems.add(encodeURI(normalizePathSep(file)))
legacyStaticFolderItems.add(encodeURIPath(normalizePathSep(file)))
}
Log.warn(
`The static directory has been deprecated in favor of the public directory. https://nextjs.org/docs/messages/static-dir-deprecated`
Expand All @@ -188,7 +189,10 @@ export async function setupFsCheck(opts: {
for (const file of await recursiveReadDir(nextStaticFolderPath)) {
// Ensure filename is encoded and normalized.
nextStaticFolderItems.add(
path.posix.join('/_next/static', encodeURI(normalizePathSep(file)))
path.posix.join(
'/_next/static',
encodeURIPath(normalizePathSep(file))
)
)
}
} catch (err) {
Expand Down Expand Up @@ -565,7 +569,7 @@ export async function setupFsCheck(opts: {
// encoded version: `/_next/static/chunks/pages/blog/%5Bslug%5D-d4858831b91b69f6.js`
try {
// encode the special characters in the path and retrieve again to determine if path exists.
const encodedCurItemPath = encodeURI(curItemPath)
const encodedCurItemPath = encodeURIPath(curItemPath)
matchedItem = items.has(encodedCurItemPath)
} catch {}
}
Expand Down
6 changes: 4 additions & 2 deletions packages/next/src/shared/lib/lazy-dynamic/preload-chunks.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use client'

import { getExpectedRequestStore } from '../../../client/components/request-async-storage.external'
import { preload } from 'react-dom'

import { getExpectedRequestStore } from '../../../client/components/request-async-storage.external'
import { encodeURIPath } from '../encode-uri-path'

export function PreloadChunks({
moduleIds,
}: {
Expand Down Expand Up @@ -34,7 +36,7 @@ export function PreloadChunks({
return (
<>
{allFiles.map((chunk) => {
const href = `${requestStore.assetPrefix}/_next/${encodeURI(chunk)}`
const href = `${requestStore.assetPrefix}/_next/${encodeURIPath(chunk)}`
const isCss = chunk.endsWith('.css')
// If it's stylesheet we use `precedence` o help hoist with React Float.
// For stylesheets we actually need to render the CSS because nothing else is going to do it so it needs to be part of the component tree.
Expand Down
7 changes: 3 additions & 4 deletions test/turbopack-build-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2881,13 +2881,12 @@
},
"test/e2e/app-dir/parallel-routes-catchall/parallel-routes-catchall.test.ts": {
"passed": [
"parallel-routes-catchall should match both the catch-all page & slot",
"parallel-routes-catchall should match correctly when defining an explicit page & slot",
"parallel-routes-catchall should match correctly when defining an explicit page but no slot",
"parallel-routes-catchall should match correctly when defining an explicit slot but no page"
],
"failed": [
"parallel-routes-catchall should match both the catch-all page & slot",
"parallel-routes-catchall should match correctly when defining an explicit page but no slot"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
Expand Down
Loading

0 comments on commit 3bba5ce

Please sign in to comment.