From 129f56d3e7e2b33b9c14d0ac51dad23a999df697 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 14 Sep 2023 15:50:59 +0200 Subject: [PATCH] more turbopack HMR fixes and test case (#55368) ### What? improve test case to check HMR reenable deduplication for server side hmr events add aggregation of client side HMR events ### Turbopack Changes * https://github.com/vercel/turbo/pull/5936 * https://github.com/vercel/turbo/pull/5948 Closes WEB-1557 --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- Cargo.lock | 74 +++++++++---------- Cargo.toml | 6 +- .../next-swc/crates/next-core/js/package.json | 4 +- packages/next/package.json | 2 +- .../next/src/server/dev/hot-reloader-types.ts | 2 +- .../src/server/lib/router-utils/setup-dev.ts | 40 ++++++---- pnpm-lock.yaml | 22 +++--- test/development/basic/tailwind-jit.test.ts | 5 +- 8 files changed, 84 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 39be91e589e41..ad0ee639a748b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -460,7 +460,7 @@ dependencies = [ [[package]] name = "auto-hash-map" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "serde", ] @@ -3719,7 +3719,7 @@ dependencies = [ [[package]] name = "node-file-trace" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "serde", @@ -7419,7 +7419,7 @@ dependencies = [ [[package]] name = "turbo-tasks" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "async-trait", @@ -7451,7 +7451,7 @@ dependencies = [ [[package]] name = "turbo-tasks-build" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "cargo-lock", @@ -7463,7 +7463,7 @@ dependencies = [ [[package]] name = "turbo-tasks-bytes" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "bytes", @@ -7478,7 +7478,7 @@ dependencies = [ [[package]] name = "turbo-tasks-env" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "dotenvs", @@ -7492,7 +7492,7 @@ dependencies = [ [[package]] name = "turbo-tasks-fetch" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -7509,7 +7509,7 @@ dependencies = [ [[package]] name = "turbo-tasks-fs" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "auto-hash-map", @@ -7539,7 +7539,7 @@ dependencies = [ [[package]] name = "turbo-tasks-hash" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "base16", "hex", @@ -7551,7 +7551,7 @@ dependencies = [ [[package]] name = "turbo-tasks-macros" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "convert_case 0.6.0", @@ -7565,7 +7565,7 @@ dependencies = [ [[package]] name = "turbo-tasks-macros-shared" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "proc-macro2", "quote", @@ -7575,7 +7575,7 @@ dependencies = [ [[package]] name = "turbo-tasks-malloc" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "mimalloc", ] @@ -7583,7 +7583,7 @@ dependencies = [ [[package]] name = "turbo-tasks-memory" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "auto-hash-map", @@ -7606,7 +7606,7 @@ dependencies = [ [[package]] name = "turbo-tasks-testing" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "auto-hash-map", @@ -7619,7 +7619,7 @@ dependencies = [ [[package]] name = "turbopack" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "async-recursion", @@ -7650,7 +7650,7 @@ dependencies = [ [[package]] name = "turbopack-bench" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "chromiumoxide", @@ -7680,7 +7680,7 @@ dependencies = [ [[package]] name = "turbopack-binding" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "auto-hash-map", "mdxjs", @@ -7723,7 +7723,7 @@ dependencies = [ [[package]] name = "turbopack-build" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -7745,7 +7745,7 @@ dependencies = [ [[package]] name = "turbopack-cli-utils" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "clap 4.4.2", @@ -7769,7 +7769,7 @@ dependencies = [ [[package]] name = "turbopack-core" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "async-recursion", @@ -7798,7 +7798,7 @@ dependencies = [ [[package]] name = "turbopack-create-test-app" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "clap 4.4.2", @@ -7811,7 +7811,7 @@ dependencies = [ [[package]] name = "turbopack-css" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "async-trait", @@ -7833,7 +7833,7 @@ dependencies = [ [[package]] name = "turbopack-dev" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -7857,7 +7857,7 @@ dependencies = [ [[package]] name = "turbopack-dev-server" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "async-compression", @@ -7894,7 +7894,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "async-trait", @@ -7928,7 +7928,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript-hmr-protocol" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "serde", "serde_json", @@ -7939,7 +7939,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript-plugins" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "async-trait", @@ -7962,7 +7962,7 @@ dependencies = [ [[package]] name = "turbopack-ecmascript-runtime" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "indoc", @@ -7979,7 +7979,7 @@ dependencies = [ [[package]] name = "turbopack-env" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "indexmap 1.9.3", @@ -7995,7 +7995,7 @@ dependencies = [ [[package]] name = "turbopack-image" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "base64 0.21.0", @@ -8015,7 +8015,7 @@ dependencies = [ [[package]] name = "turbopack-json" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "serde", @@ -8030,7 +8030,7 @@ dependencies = [ [[package]] name = "turbopack-mdx" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "mdxjs", @@ -8045,7 +8045,7 @@ dependencies = [ [[package]] name = "turbopack-node" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "async-stream", @@ -8080,7 +8080,7 @@ dependencies = [ [[package]] name = "turbopack-static" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "serde", @@ -8096,7 +8096,7 @@ dependencies = [ [[package]] name = "turbopack-swc-utils" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "swc_core", "turbo-tasks", @@ -8107,7 +8107,7 @@ dependencies = [ [[package]] name = "turbopack-test-utils" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "once_cell", @@ -8125,7 +8125,7 @@ dependencies = [ [[package]] name = "turbopack-wasm" version = "0.1.0" -source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230908.2#b46996f30fe46370e6f7d9bc0907725ea2add792" +source = "git+https://github.com/vercel/turbo.git?tag=turbopack-230914.2#9c3e2d9ec3233bedd9c532e43d66c9fcd4feb3a2" dependencies = [ "anyhow", "indexmap 1.9.3", diff --git a/Cargo.toml b/Cargo.toml index e3004c2268cfb..ef20a93c0d4ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,11 +42,11 @@ swc_core = { version = "=0.79.55", features = ["ecma_loader_lru", "ecma_loader_p testing = { version = "0.33.21" } # Turbo crates -turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230908.2" } +turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230914.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-230908.2" } +turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230914.2" } # [TODO]: need to refactor embed_directory! macro usage in next-core -turbo-tasks-fs= { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230908.2" } +turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230914.2" } # General Deps diff --git a/packages/next-swc/crates/next-core/js/package.json b/packages/next-swc/crates/next-core/js/package.json index 8adb88b2b79a5..e373090a8d8f6 100644 --- a/packages/next-swc/crates/next-core/js/package.json +++ b/packages/next-swc/crates/next-core/js/package.json @@ -10,8 +10,8 @@ "check": "tsc --noEmit" }, "dependencies": { - "@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230901.3", - "@vercel/turbopack-node": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230901.3", + "@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230914.2", + "@vercel/turbopack-node": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230914.2", "anser": "^2.1.1", "css.escape": "^1.5.1", "next": "*", diff --git a/packages/next/package.json b/packages/next/package.json index 38c5a0600df9e..972589929f893 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -193,7 +193,7 @@ "@types/ws": "8.2.0", "@vercel/ncc": "0.34.0", "@vercel/nft": "0.22.6", - "@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230901.3", + "@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230914.2", "acorn": "8.5.0", "ajv": "8.11.0", "amphtml-validator": "1.0.35", diff --git a/packages/next/src/server/dev/hot-reloader-types.ts b/packages/next/src/server/dev/hot-reloader-types.ts index 120cfc5e248cc..7428e426001ee 100644 --- a/packages/next/src/server/dev/hot-reloader-types.ts +++ b/packages/next/src/server/dev/hot-reloader-types.ts @@ -30,7 +30,7 @@ interface ServerErrorAction { interface TurboPackMessageAction { type: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE - data: TurbopackUpdate + data: TurbopackUpdate | TurbopackUpdate[] } interface BuildingAction { diff --git a/packages/next/src/server/lib/router-utils/setup-dev.ts b/packages/next/src/server/lib/router-utils/setup-dev.ts index 60e8f4a465466..796e2a0c2d76e 100644 --- a/packages/next/src/server/lib/router-utils/setup-dev.ts +++ b/packages/next/src/server/lib/router-utils/setup-dev.ts @@ -102,6 +102,7 @@ import { ReloadPageAction, TurboPackConnectedAction, } from '../../dev/hot-reloader-types' +import type { Update as TurbopackUpdate } from '../../../build/swc' import { debounce } from '../../utils' import { deleteAppClientCache, @@ -227,7 +228,8 @@ async function startWatcher(opts: SetupOpts) { let currentEntriesHandling = new Promise( (resolve) => (currentEntriesHandlingResolve = resolve) ) - const hmrPayloads = new Map() + const hmrPayloads = new Map() + const turbopackUpdates: TurbopackUpdate[] = [] let hmrBuilding = false const issues = new Map>() @@ -362,12 +364,17 @@ async function startWatcher(opts: SetupOpts) { hmrBuilding = false if (errors.size === 0) { - for (const payloads of hmrPayloads.values()) { - for (const payload of payloads) { - hotReloader.send(payload) - } + for (const payload of hmrPayloads.values()) { + hotReloader.send(payload) } hmrPayloads.clear() + if (turbopackUpdates.length > 0) { + hotReloader.send({ + type: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE, + data: turbopackUpdates, + }) + turbopackUpdates.length = 0 + } } }, 2) @@ -379,13 +386,19 @@ async function startWatcher(opts: SetupOpts) { hotReloader.send({ action: HMR_ACTIONS_SENT_TO_BROWSER.BUILDING }) hmrBuilding = true } - let k = `${key}:${id}` - let list = hmrPayloads.get(k) - if (!list) { - list = [] - hmrPayloads.set(k, list) + hmrPayloads.set(`${key}:${id}`, payload) + sendHmrDebounce() + } + + function sendTurbopackMessage(payload: TurbopackUpdate) { + // We've detected a change in some part of the graph. If nothing has + // been inserted into building yet, then this is the first change + // emitted, but their may be many more coming. + if (!hmrBuilding) { + hotReloader.send({ action: HMR_ACTIONS_SENT_TO_BROWSER.BUILDING }) + hmrBuilding = true } - list.push(payload) + turbopackUpdates.push(payload) sendHmrDebounce() } @@ -845,10 +858,7 @@ async function startWatcher(opts: SetupOpts) { for await (const data of subscription) { processIssues(id, data) - sendHmr('hmr-event', id, { - type: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE, - data, - }) + sendTurbopackMessage(data) } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9341ed3c01952..ee7425b59b7a2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1064,8 +1064,8 @@ importers: specifier: 0.22.6 version: 0.22.6 '@vercel/turbopack-ecmascript-runtime': - specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230901.3 - version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230901.3(react-refresh@0.12.0)(webpack@5.86.0)' + specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230914.2 + version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230914.2(react-refresh@0.12.0)(webpack@5.86.0)' acorn: specifier: 8.5.0 version: 8.5.0 @@ -1530,11 +1530,11 @@ importers: packages/next-swc/crates/next-core/js: dependencies: '@vercel/turbopack-ecmascript-runtime': - specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230901.3 - version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230901.3(react-refresh@0.12.0)(webpack@5.86.0)' + specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230914.2 + version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230914.2(react-refresh@0.12.0)(webpack@5.86.0)' '@vercel/turbopack-node': - specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230901.3 - version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230901.3' + specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230914.2 + version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230914.2' anser: specifier: ^2.1.1 version: 2.1.1 @@ -27225,9 +27225,9 @@ packages: /zwitch@2.0.4: resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} - '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230901.3(react-refresh@0.12.0)(webpack@5.86.0)': - resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230901.3} - id: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230901.3' + '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230914.2(react-refresh@0.12.0)(webpack@5.86.0)': + resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230914.2} + id: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230914.2' name: '@vercel/turbopack-ecmascript-runtime' version: 0.0.0 dependencies: @@ -27237,8 +27237,8 @@ packages: - react-refresh - webpack - '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230901.3': - resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230901.3} + '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230914.2': + resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230914.2} name: '@vercel/turbopack-node' version: 0.0.0 dependencies: diff --git a/test/development/basic/tailwind-jit.test.ts b/test/development/basic/tailwind-jit.test.ts index 533cd10ebc94d..53fec6fb50d84 100644 --- a/test/development/basic/tailwind-jit.test.ts +++ b/test/development/basic/tailwind-jit.test.ts @@ -2,6 +2,7 @@ import { join } from 'path' import webdriver from 'next-webdriver' import { FileRef, nextTestSetup } from 'e2e-utils' import { check, shouldRunTurboDevTest } from 'next-test-utils' +import { BrowserInterface } from 'test/lib/browsers/base' // [TODO]: It is unclear why turbopack takes longer to run this test // remove once it's fixed @@ -27,7 +28,7 @@ describe('TailwindCSS JIT', () => { }) it('works with JIT enabled', async () => { - let browser + let browser: BrowserInterface try { browser = await webdriver(next.url, '/') const text = await browser.elementByCss('.text-6xl').text() @@ -44,6 +45,7 @@ describe('TailwindCSS JIT', () => { '', '' ) + await browser.eval('window.REAL_HMR = 1;') // change the content try { @@ -52,6 +54,7 @@ describe('TailwindCSS JIT', () => { () => browser.elementByCss('#test-link').getComputedCss('color'), /rgb\(220, 38, 38\)/ ) + expect(await browser.eval('window.REAL_HMR')).toBe(1) } finally { // add the original content await next.patchFile(aboutPagePath, originalContent)