Skip to content

Commit

Permalink
feat(nextjs): No ezheaders (#4706)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekradko authored Dec 4, 2024
1 parent 008752d commit 20d8571
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-bugs-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/nextjs': minor
---

Remove usage of `ezheaders`
1 change: 0 additions & 1 deletion packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"@clerk/shared": "workspace:*",
"@clerk/types": "workspace:*",
"crypto-js": "4.2.0",
"ezheaders": "0.1.0",
"server-only": "0.0.1",
"tslib": "catalog:repo"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/src/app-router/server-actions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use server';

import { getCookies } from 'ezheaders';
import { cookies } from 'next/headers';

// This function needs to be async as we'd like to support next versions in the range of [14.1.2,14.2.0)
// These versions required 'use server' files to export async methods only. This check was later relaxed
// and the async is no longer required in newer next versions.
// ref: https://github.com/vercel/next.js/pull/62821
export async function invalidateCacheAction(): Promise<void> {
void (await getCookies()).delete(`__clerk_invalidate_cache_cookie_${Date.now()}`);
void (await cookies()).delete(`__clerk_invalidate_cache_cookie_${Date.now()}`);
}
4 changes: 2 additions & 2 deletions packages/nextjs/src/app-router/server/ClerkProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AuthObject } from '@clerk/backend';
import type { InitialState, Without } from '@clerk/types';
import { header } from 'ezheaders';
import { headers } from 'next/headers';
import nextPkg from 'next/package.json';
import React from 'react';

Expand All @@ -21,7 +21,7 @@ const getDynamicClerkState = React.cache(async function getDynamicClerkState() {
});

const getNonceFromCSPHeader = React.cache(async function getNonceFromCSPHeader() {
return getScriptNonceFromHeader((await header('Content-Security-Policy')) || '') || '';
return getScriptNonceFromHeader((await headers()).get('Content-Security-Policy') || '') || '';
});

export async function ClerkProvider(
Expand Down
7 changes: 4 additions & 3 deletions packages/nextjs/src/app-router/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export const isPrerenderingBailout = (e: unknown) => {
export async function buildRequestLike() {
try {
// Dynamically import next/headers, otherwise Next12 apps will break
// @ts-ignore: Cannot find module 'next/headers' or its corresponding type declarations.ts(2307)
const { getHeaders } = await import('ezheaders');
return new NextRequest('https://placeholder.com', { headers: await getHeaders() });
// @ts-expect-error: Cannot find module 'next/headers' or its corresponding type declarations.ts(2307)
const { headers } = await import('next/headers');
const resolvedHeaders = await headers();
return new NextRequest('https://placeholder.com', { headers: resolvedHeaders });
} catch (e: any) {
// rethrow the error when react throws a prerendering bailout
// https://nextjs.org/docs/messages/ppr-caught-error
Expand Down
12 changes: 0 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 20d8571

Please sign in to comment.