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

Introduce NextMode #49852

Merged
merged 15 commits into from
May 17, 2023
67 changes: 34 additions & 33 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_core = { version = "0.76.6" }
testing = { version = "0.33.10" }

# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230516.1" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230517.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-230516.1" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230517.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230516.1" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230517.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-230516.1",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230516.1",
"@vercel/turbopack-dev": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230517.2",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230517.2",
"anser": "^2.1.1",
"css.escape": "^1.5.1",
"next": "*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* This is the runtime entry point for Next.js client-side bundles.
*/

import './shims'
import 'next/dist/client/next'
11 changes: 11 additions & 0 deletions packages/next-swc/crates/next-core/js/src/build/client/shims.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import '../shims'

// Next uses __webpack_require__ extensively.
globalThis.__webpack_require__ = (name) => {
console.error(
`__webpack_require__ is not implemented (when requiring ${name})`
)
}

// initialize() needs `__webpack_public_path__` to be defined.
globalThis.__webpack_public_path__ = undefined
3 changes: 3 additions & 0 deletions packages/next-swc/crates/next-core/js/src/build/shims.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This ensures Next.js uses React 18's APIs (hydrateRoot) instead of React 17's
// (hydrate).
process.env.__NEXT_REACT_ROOT = 'true'
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ async function loadPageChunk(assetPrefix: string, chunkData: ChunkData) {

window.next = {
version: version || '',
// @ts-expect-error
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started getting a TS error from this, saying there was no error there. I think our types might be busted in this package. In any case, I tried to improve our typing a bit (see above).

get router() {
return router
},
Expand Down
7 changes: 6 additions & 1 deletion packages/next-swc/crates/next-core/js/types/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { Router } from 'next/dist/client/router'
import type { MittEmitter } from 'next/dist/shared/lib/mitt'

declare global {
type ChunkData =
| string
Expand All @@ -20,7 +23,9 @@ declare global {
)[]
var next: {
version: string
appDir: boolean
appDir?: boolean
router?: Router
emitter?: MittEmitter<string>
}

function __turbopack_load_page_chunks__(
Expand Down