Skip to content

Conversation

@jantimon
Copy link
Contributor

@jantimon jantimon commented Feb 6, 2026

This adds this._compilation to the webpack loader context in turbopack.

In webpack, loaders can use this._compilation as a WeakMap key to cache expensive work for the duration of a compilation. This is useful for loaders that evaluate shared dependencies — e.g. next-yak evaluates design token files for every component that uses them, and without per-compilation caching the same file gets evaluated once per dependent component per batch.

The implementation piggybacks on the existing file watcher batching. A u64 counter on DiskFileSystemInner increments on each batch flush and gets passed through the IPC Evaluate message to the Node.js loader process. The counter is deliberately kept out of WebpackLoaderContext.args so it doesn't affect turbo-tasks memoization. On the JS side, a new frozen object is created whenever the counter changes.

Includes an e2e test that verifies the object is shared within a batch and changes between batches.

Fixes #89599

@nextjs-bot nextjs-bot added tests Turbopack Related to Turbopack with Next.js. labels Feb 6, 2026
@nextjs-bot
Copy link
Collaborator

Allow CI Workflow Run

  • approve CI run for commit: 08e15ac

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 6, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing jantimon:turbopack-webpack-loader-compilation-object (08e15ac) with canary (a91b360)

Summary

✅ 17 untouched benchmarks
⏩ 3 skipped benchmarks1

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Turbopack Related to Turbopack with Next.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose this._compilation to webpack loaders in Turbopack

2 participants