Skip to content

Commit

Permalink
replace defined values and add __NEXT_HAS_REWRITES define (#48628)
Browse files Browse the repository at this point in the history
### What?

This fixes a problem when the router fails to load the correct JS file
from the page_loader and opts out to full refresh

### Why?

The router behaves incorrect when `__NEXT_HAS_REWRITES` is missing in
turbopack

### How?

see also vercel/turborepo#4652

### Turbopack changes

* vercel/turborepo#4650 <!-- Tobias Koppers - reduce
size of TypeType from 32bytes to 16bytes -->
* vercel/turborepo#4648 <!-- Tobias Koppers - handle
chunk register in the sync runtime.none correctly -->
* vercel/turborepo#4609 <!-- OJ Kwon -
fix(ecmascript): eval assignop to the ident -->
* vercel/turborepo#4652 <!-- Tobias Koppers - allow
to pass constant values to free var references -->
* vercel/turborepo#4649 <!-- Tobias Koppers - Image
processing improvements -->
  • Loading branch information
sokra authored Apr 20, 2023
1 parent 8ab6c4c commit ec385de
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 65 deletions.
64 changes: 32 additions & 32 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.5" }
testing = { version = "0.33.4" }

# Turbo crates
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230419.4" }
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230420.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-230419.4" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230420.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230419.4" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230420.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-230419.4",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230419.4",
"@vercel/turbopack-dev": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230420.2",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230420.2",
"anser": "^2.1.1",
"css.escape": "^1.5.1",
"next": "*",
Expand Down
26 changes: 18 additions & 8 deletions packages/next-swc/crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use turbo_binding::{
chunk::ChunkingContextVc,
compile_time_defines,
compile_time_info::{
CompileTimeDefinesVc, CompileTimeInfo, CompileTimeInfoVc, FreeVarReference,
FreeVarReferencesVc,
CompileTimeDefines, CompileTimeDefinesVc, CompileTimeInfo, CompileTimeInfoVc,
FreeVarReference, FreeVarReferencesVc,
},
context::AssetContextVc,
environment::{
Expand Down Expand Up @@ -53,17 +53,27 @@ use crate::{
util::foreign_code_context_condition,
};

pub fn next_client_defines() -> CompileTimeDefinesVc {
fn defines() -> CompileTimeDefines {
compile_time_defines!(
process.turbopack = true,
process.env.NODE_ENV = "development",
process.env.__NEXT_CLIENT_ROUTER_FILTER_ENABLED = false
process.env.__NEXT_CLIENT_ROUTER_FILTER_ENABLED = false,
process.env.__NEXT_HAS_REWRITES = true,
process.env.__NEXT_I18N_SUPPORT = false,
)
.cell()
// TODO(WEB-937) there are more defines needed, see
// packages/next/src/build/webpack-config.ts
}

pub fn next_client_free_vars() -> FreeVarReferencesVc {
free_var_references!(
#[turbo_tasks::function]
pub fn next_client_defines() -> CompileTimeDefinesVc {
defines().cell()
}

#[turbo_tasks::function]
pub async fn next_client_free_vars() -> Result<FreeVarReferencesVc> {
Ok(free_var_references!(
..defines().into_iter(),
Buffer = FreeVarReference::EcmaScriptModule {
request: "node:buffer".to_string(),
context: None,
Expand All @@ -75,7 +85,7 @@ pub fn next_client_free_vars() -> FreeVarReferencesVc {
export: Some("default".to_string()),
}
)
.cell()
.cell())
}

#[turbo_tasks::function]
Expand Down
Loading

0 comments on commit ec385de

Please sign in to comment.