Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app dir fixes #48025

Merged
merged 12 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 31 additions & 31 deletions packages/next-swc/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 packages/next-swc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ swc_emotion = { version = "0.29.10" }
testing = { version = "0.31.31" }

# Turbo crates
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230414.4" }
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230417.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-230414.4" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230417.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230414.4" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230417.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-230414.4",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230414.4",
"@vercel/turbopack-dev": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230417.2",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230417.2",
"anser": "^2.1.1",
"css.escape": "^1.5.1",
"next": "*",
Expand Down
49 changes: 34 additions & 15 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 @@ -23,9 +23,6 @@ import type {
import type { RenderData } from 'types/turbopack'
import type { RenderOpts } from 'next/dist/server/app-render/types'

import 'next/dist/server/node-polyfill-fetch'
import 'next/dist/server/node-polyfill-web-streams'
import '../polyfill/async-local-storage'
sokra marked this conversation as resolved.
Show resolved Hide resolved
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'
Expand Down Expand Up @@ -127,7 +124,6 @@ type LoaderTree = [
]

async function runOperation(renderData: RenderData) {
const layoutInfoChunks: Record<string, string[]> = {}
let tree: LoaderTree = LOADER_TREE

const proxyMethodsForModule = (
Expand Down Expand Up @@ -167,7 +163,7 @@ async function runOperation(renderData: RenderData) {
id = key.slice(0, pos)
name = key.slice(pos + 1)
} else {
throw new Error('key need to be in format of ${file}#${name}')
throw new Error('keys need to be formatted as {file}#{name}')
}

return {
Expand Down Expand Up @@ -203,19 +199,45 @@ async function runOperation(renderData: RenderData) {
},
}
}
const availableModules = new Set()
const toPath = (chunk: ChunkData) =>
typeof chunk === 'string' ? chunk : chunk.path
/// determines if a chunk is needed based on the current available modules
const filterAvailable = (chunk: ChunkData) => {
sokra marked this conversation as resolved.
Show resolved Hide resolved
if (typeof chunk === 'string') {
return true
} else {
let includedList = chunk.included || []
if (includedList.length === 0) {
return true
}
let needed = false
for (const item of includedList) {
if (!availableModules.has(item)) {
availableModules.add(item)
needed = true
}
}
return needed
}
}
const cssFilesProxyMethods = {
get(_target: any, prop: string) {
const chunks = JSON.parse(prop)
const cssChunks = chunks.filter((path: string) => path.endsWith('.css'))
return cssChunks
const cssChunks = JSON.parse(prop)
// TODO(WEB-856) subscribe to changes
return cssChunks.map(toPath)
},
}
const cssImportProxyMethods = {
get(_target: any, prop: string) {
const chunks = JSON.parse(prop.replace(/\.js$/, ''))
const cssChunks = JSON.parse(prop.replace(/\.js$/, ''))
// TODO(WEB-856) subscribe to changes

const cssChunks = chunks.filter((path: string) => path.endsWith('.css'))
return cssChunks.map((chunk: string) => JSON.stringify([chunk, [chunk]]))
// This return value is passed to proxyMethodsNested for clientModules
return cssChunks
.filter(filterAvailable)
.map(toPath)
.map((chunk: string) => JSON.stringify([chunk, [chunk]]))
},
}
const manifest: ClientReferenceManifest = new Proxy({} as any, proxyMethods())
Expand All @@ -241,10 +263,7 @@ async function runOperation(renderData: RenderData) {
dev: true,
buildManifest: {
polyfillFiles: [],
rootMainFiles: Object.values(layoutInfoChunks)
.flat()
.concat(BOOTSTRAP)
.filter((path) => path.endsWith('.js')),
rootMainFiles: BOOTSTRAP.filter((path) => path.endsWith('.js')),
devFiles: [],
ampDevFiles: [],
lowPriorityFiles: [],
Expand Down