Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/flags/src/next/dedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ export function dedupe<A extends Array<unknown>, T>(
): (...args: A) => Promise<T> {
const requestStore: RequestStore<T> = new WeakMap<Headers, CacheNode<T>>();

// async import required as turbopack errors in Pages Router
// when next/headers is imported at the top-level
const headersPromise = import('next/headers').then((mod) => mod.headers);
Copy link
Collaborator

@dferber90 dferber90 Oct 13, 2025

Choose a reason for hiding this comment

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

I have not tested, but I believe this would lead to an issue in Pages Router, as we can currently do the following at the top level

const foo = dedupe(() => Math.random())

The next/headers import would originally only happen once foo is called. But with this change we would now cause the import of next/headers even if foo is not called.


const dedupedFn = async function (this: unknown, ...args: A): Promise<T> {
// async import required as turbopack errors in Pages Router
// when next/headers is imported at the top-level
const { headers } = await import('next/headers');
const headers = await headersPromise;

const h = await headers();
let cacheNode = requestStore.get(h);
Expand Down
Loading