Skip to content

fix(nextjs): Remove sourcemaps from bundled server-actions #3773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .changeset/pretty-lies-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
5 changes: 5 additions & 0 deletions .changeset/slow-needles-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/nextjs": patch
---

Stop throwing "Error: Clerk: auth() was called but Clerk can't detect usage of authMiddleware()." errors when no user action is needed by removing sourcemaps for all Clerk-bundled server actions.
4 changes: 2 additions & 2 deletions packages/nextjs/src/app-router/client/ClerkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ClerkNextOptionsProvider } from '../../client-boundary/NextOptionsConte
import type { NextClerkProviderProps } from '../../types';
import { ClerkJSScript } from '../../utils/clerk-js-script';
import { mergeNextClerkPropsWithEnv } from '../../utils/mergeNextClerkPropsWithEnv';
import { invalidateCacheAction } from '../server-actions/invalidateCache';
import { invalidateCacheAction } from '../server-actions';
import { useAwaitablePush } from './useAwaitablePush';
import { useAwaitableReplace } from './useAwaitableReplace';

Expand Down Expand Up @@ -61,7 +61,7 @@ export const ClientClerkProvider = (props: NextClerkProviderProps) => {
if (window.next?.version && typeof window.next.version === 'string' && window.next.version.startsWith('13')) {
router.refresh();
} else {
invalidateCacheAction();
void invalidateCacheAction();
}
});
});
Expand Down
23 changes: 21 additions & 2 deletions packages/nextjs/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig(overrideOptions => {
const shouldPublish = !!overrideOptions.env?.publish;

const common: Options = {
entry: ['./src/**/*.{ts,tsx,js,jsx}', '!./src/**/*.test.{ts,tsx}'],
entry: ['./src/**/*.{ts,tsx,js,jsx}', '!./src/**/*.test.{ts,tsx}', '!./src/**/server-actions.ts'],
// We want to preserve original file structure
// so that the "use client" directives are not lost
// and make debugging easier via node_modules easier
Expand All @@ -37,12 +37,31 @@ export default defineConfig(overrideOptions => {
outDir: './dist/cjs',
};

const serverActionsEsm: Options = {
...esm,
entry: ['./src/**/server-actions.ts'],
sourcemap: false,
};

const serverActionsCjs: Options = {
...cjs,
entry: ['./src/**/server-actions.ts'],
sourcemap: false,
};

const copyPackageJson = (format: 'esm' | 'cjs') => `cp ./package.${format}.json ./dist/${format}/package.json`;
// Tsup will not output the generated file in the same location as the source file
// So we need to move the server-actions.js file to the app-router folder manually
// Happy to improve this if there is a better way
const moveServerActions = (format: 'esm' | 'cjs') =>
`mv ./dist/${format}/server-actions.js ./dist/${format}/app-router`;

return runAfterLast([
'npm run build:declarations',
copyPackageJson('esm'),
copyPackageJson('cjs'),
moveServerActions('esm'),
moveServerActions('cjs'),
shouldPublish && 'npm run publish:local',
])(esm, cjs);
])(esm, cjs, serverActionsEsm, serverActionsCjs);
});
Loading