Skip to content

Conversation

@dstaley
Copy link
Member

@dstaley dstaley commented May 19, 2025

Description

(This PR is technically a draft; the pr.pkg.new workflow doesn't run on draft PRs.)

This experimental PR adds support for building a "bundleless" version of clerk-js, specifically the ESM build. More details to come if this experiment proves successful!

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Chores
    • Updated build configuration and dependencies to improve bundling and support for React and SVG assets.
    • Introduced a new build system configuration for ES module output targeting web environments.
    • Removed an outdated module build configuration to streamline the build process.
    • Improved documentation formatting by removing an extraneous blank line.

@changeset-bot
Copy link

changeset-bot bot commented May 19, 2025

⚠️ No Changeset found

Latest commit: ab31e3a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented May 19, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 4, 2025 2:52pm

@dstaley dstaley marked this pull request as ready for review May 19, 2025 20:58
"main": "dist/clerk.js",
"jsdelivr": "dist/clerk.browser.js",
"module": "dist/clerk.mjs",
"module": "dist/esm/index.mjs",
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be a breaking change in some cases ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this would only break if someone was importing directly from dist/. The only reason this is in a folder is because Rslib will, for some reason, run on all files in the input folder. So it would emit index.browser.js which was confusing. Not a strong suggestion that we do it this way, just wanted to get it working for experimental purposes!

@dstaley dstaley closed this May 19, 2025
@dstaley dstaley reopened this May 19, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented May 19, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@5964

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@5964

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@5964

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@5964

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@5964

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@5964

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@5964

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@5964

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@5964

@clerk/express

npm i https://pkg.pr.new/@clerk/express@5964

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@5964

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@5964

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@5964

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@5964

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@5964

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@5964

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@5964

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@5964

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@5964

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@5964

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@5964

@clerk/types

npm i https://pkg.pr.new/@clerk/types@5964

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@5964

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@5964

commit: ab31e3a

@dstaley
Copy link
Member Author

dstaley commented Jun 4, 2025

currently blocked by web-infra-dev/rslib#1007 and web-infra-dev/rslib#882

@clerk-cookie
Copy link
Collaborator

Hello 👋

We currently close PRs after 60 days of inactivity. It's been 50 days since the last update here. If we missed this PR, please reply here. Otherwise, we'll close this PR in 10 days.

Thanks for being a part of the Clerk community! 🙏

@clerk-cookie clerk-cookie added Stale and removed Stale labels Jul 25, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 25, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new build system configuration for the @clerk/clerk-js package by adding an rslib.config.ts file, which sets up ES module output, plugins for React and SVG handling, and various compile-time constants. The package.json is updated to change the module entry point, modify the build script to include an additional build step using rslib, and add new development dependencies related to the new build process. The existing rspack.config.js is modified to remove the clerkEsm configuration and its usage, indicating a shift away from Rspack-based ES module bundling in favor of the new rslib-based approach. Additionally, a minor formatting fix is applied in the integration README by removing an extraneous blank line.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Complexity is low to moderate due to the introduction of a new build configuration, straightforward package.json edits, removal of a configuration block, and a minor documentation formatting change.
  • Review focuses on verifying build pipeline changes, dependency updates, configuration correctness, and ensuring no regressions in build outputs or documentation clarity, with no direct changes to application logic or exports.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (2)
packages/clerk-js/package.json (1)

1-104: No tests cover the new bundleless output

The PR alters the public ESM entry and introduces a second build pipeline yet adds no automated checks. Consider adding at least one Jest/TS test that:

import pkg from '../dist/esm/index.mjs';
expect(pkg).toBeDefined();

to assert the file exists and loads without syntax errors.

packages/clerk-js/rslib.config.ts (1)

1-42: Missing test/build smoke checks for rslib output

Similar to the package.json feedback, please add CI smoke tests that import a component from dist/esm to detect tree-shaking / JSX transform regressions early.

♻️ Duplicate comments (1)
packages/clerk-js/package.json (1)

24-27: Potential breaking change – new module entry path

Changing the ESM entry from dist/clerk.mjs to dist/esm/index.mjs can break consumers that import directly from the previous path (e.g. import … from "@clerk/clerk-js/dist/clerk.mjs"). Although unofficial paths are discouraged, they do exist in the wild.

Please confirm whether:

  1. dist/esm/index.mjs is generated by the new build and published.
  2. A deprecation notice or compatibility shim is required.
🧹 Nitpick comments (3)
packages/clerk-js/package.json (1)

34-38: Build script now performs two full builds – consider sequencing & caching

"build:bundle": "pnpm clean && rspack … && rslib build" means
1️⃣ clean → 2️⃣ Rspack build (CJS, UMD, etc.) → 3️⃣ Rslib ESM build.
Running two full compilers back-to-back significantly increases CI time and can double compile-time type-checking.

Optional refactor: invoke rslib first, then reuse TS program outputs (or at least skip tsc inside rslib) to avoid duplicate work, or gate the second build behind an env flag while the experiment is in flight.

packages/clerk-js/rslib.config.ts (2)

1-5: Sort import groups to satisfy ESLint / simple-import-sort

ESLint reports unsorted imports. Apply:

-import { defineConfig } from '@rslib/core';
-import { pluginReact } from '@rsbuild/plugin-react';
-import { pluginSvgr } from '@rsbuild/plugin-svgr';
+import { defineConfig } from '@rslib/core';
+import { pluginReact } from '@rsbuild/plugin-react';
+import { pluginSvgr } from '@rsbuild/plugin-svgr';
+
 import packageJSON from './package.json';

(Only the blank line needs moving.)


9-18: Hard-coding production flags removes flexibility

All compile-time constants are set to production values. For local debugging a bundleless dev build could be handy. Consider parameterising via process.env.BUILD_ENV (defaulting to production) so rslib build --mode development remains possible.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d35ae3 and 8d463e2.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • packages/clerk-js/package.json (3 hunks)
  • packages/clerk-js/rslib.config.ts (1 hunks)
  • packages/clerk-js/rspack.config.js (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/clerk-js/rspack.config.js
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/clerk-js/package.json
  • packages/clerk-js/rslib.config.ts
packages/*/package.json

📄 CodeRabbit Inference Engine (.cursor/rules/global.mdc)

All publishable packages should be placed under the packages/ directory

packages/*/package.json: All publishable packages must be located in the 'packages/' directory.
All packages must be published under the @clerk namespace on npm.
Semantic versioning must be used across all packages.

Files:

  • packages/clerk-js/package.json
**/*

⚙️ CodeRabbit Configuration File

**/*: If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

Whenever reviewing a pull request, if there are any changes that could impact security, always tag @clerk/security in the PR.

Security-impacting changes include, but are not limited to:

  • Changes to authentication logic or mechanisms (e.g. login, session handling, token issuance)
  • Any modification to access control, authorization checks, or role-based permissions
  • Introduction or modification of hashing algorithms, signature verification, or cryptographic primitives
  • Handling of sensitive data (e.g. passwords, tokens, secrets, PII)
  • Integration with external identity providers (e.g. SSO, OAuth, OpenID Connect)
  • Modifications to security headers, cookie flags, CORS policies, or CSRF protections
  • Bypass mechanisms (e.g. feature flags, testing overrides) that could weaken protections
  • Changes to rate limiting, abuse prevention, or input validation

If you're unsure whether a change is security-relevant, err on the side of caution and tag @clerk/security.

Any time that you tag @clerk/security, please do so explicitly in a code comment, rather than within a collapsed section in a coderabbit comment, such as the "recent review details" section. If you do use the team name in any thinking or non-direct-code-comment content, it can be referred to as "clerk security team" to avoid accidentally printing the tag which sends a notification to the team.

Files:

  • packages/clerk-js/package.json
  • packages/clerk-js/rslib.config.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/clerk-js/rslib.config.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/clerk-js/rslib.config.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/clerk-js/rslib.config.ts
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/clerk-js/rslib.config.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/clerk-js/rslib.config.ts
🧬 Code Graph Analysis (1)
packages/clerk-js/rslib.config.ts (1)
packages/clerk-js/rspack.config.js (1)
  • packageJSON (3-3)
🪛 ESLint
packages/clerk-js/rslib.config.ts

[error] 1-5: Run autofix to sort these imports!

(simple-import-sort/imports)

🔇 Additional comments (4)
packages/clerk-js/package.json (1)

82-86: Verify dev-dependency alignment & workspace hoisting

The three new packages (@rsbuild/plugin-react, @rsbuild/plugin-svgr, @rslib/core) are added as devDependencies here.
• If any of them are required at runtime (e.g. imported by generated code), they must move to dependencies.
• Ensure the root workspace installs matching versions to avoid duplication in lockfiles.

packages/clerk-js/rslib.config.ts (3)

5-5: Ensure TS config supports JSON imports

import packageJSON from './package.json' requires resolveJsonModule: true in the package’s tsconfig.json. Verify this flag is enabled, otherwise the build will fail under strict TS compilation.


20-26: ESM output path matches package.json – looks good

lib.format = 'esm' with bundle: false and distPath.root = './dist/esm' aligns with the updated "module" field. ✅


31-39: React SWC options – double-check automatic runtime + Emotion

Using runtime: 'automatic' with importSource: '@emotion/react' is correct for Emotion 11, but it disables React Refresh. Ensure this is intentional; otherwise set refresh: true in non-prod builds.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/clerk-js/rslib.config.ts (2)

1-6: Fix import-order violation flagged by ESLint

simple-import-sort reports a deterministic ordering issue (Lines 1-5). Run the fixer or manually re-order the groups to keep CI green.

-import { defineConfig } from '@rslib/core';
-import { pluginReact } from '@rsbuild/plugin-react';
-import { pluginSvgr } from '@rsbuild/plugin-svgr';
-
-import packageJSON from './package.json';
+import { defineConfig } from '@rslib/core';
+import { pluginReact } from '@rsbuild/plugin-react';
+import { pluginSvgr } from '@rsbuild/plugin-svgr';
+
+import packageJSON from './package.json';

19-20: Avoid hard-coding environment flags to “production”

Locking process.env.NODE_ENV and process.env.CLERK_ENV to 'production' at build time prevents tree-shaking or debugging builds that rely on the actual environment. Consider forwarding the current env with a fallback:

-      'process.env.CLERK_ENV': JSON.stringify('production'),
-      'process.env.NODE_ENV': JSON.stringify('production'),
+      'process.env.CLERK_ENV': JSON.stringify(process.env.CLERK_ENV ?? 'production'),
+      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV ?? 'production'),

This preserves existing behaviour while keeping the config flexible for dev/test pipelines.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 01570ae and 80bec90.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • packages/clerk-js/rslib.config.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/clerk-js/rslib.config.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/clerk-js/rslib.config.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/clerk-js/rslib.config.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/clerk-js/rslib.config.ts
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/clerk-js/rslib.config.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/clerk-js/rslib.config.ts
**/*

⚙️ CodeRabbit Configuration File

**/*: If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.

Whenever reviewing a pull request, if there are any changes that could impact security, always tag @clerk/security in the PR.

Security-impacting changes include, but are not limited to:

  • Changes to authentication logic or mechanisms (e.g. login, session handling, token issuance)
  • Any modification to access control, authorization checks, or role-based permissions
  • Introduction or modification of hashing algorithms, signature verification, or cryptographic primitives
  • Handling of sensitive data (e.g. passwords, tokens, secrets, PII)
  • Integration with external identity providers (e.g. SSO, OAuth, OpenID Connect)
  • Modifications to security headers, cookie flags, CORS policies, or CSRF protections
  • Bypass mechanisms (e.g. feature flags, testing overrides) that could weaken protections
  • Changes to rate limiting, abuse prevention, or input validation

If you're unsure whether a change is security-relevant, err on the side of caution and tag @clerk/security.

Any time that you tag @clerk/security, please do so explicitly in a code comment, rather than within a collapsed section in a coderabbit comment, such as the "recent review details" section. If you do use the team name in any thinking or non-direct-code-comment content, it can be referred to as "clerk security team" to avoid accidentally printing the tag which sends a notification to the team.

Files:

  • packages/clerk-js/rslib.config.ts
🧬 Code Graph Analysis (1)
packages/clerk-js/rslib.config.ts (1)
packages/clerk-js/rspack.config.js (1)
  • packageJSON (3-3)
🪛 ESLint
packages/clerk-js/rslib.config.ts

[error] 1-5: Run autofix to sort these imports!

(simple-import-sort/imports)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)

Comment on lines +12 to +21
define: {
__DEV__: false,
__PKG_NAME__: JSON.stringify(packageJSON.name),
__PKG_VERSION__: JSON.stringify(packageJSON.version),
__BUILD_FLAG_KEYLESS_UI__: false,
__BUILD_DISABLE_RHC__: JSON.stringify('false'),
__BUILD_VARIANT_CHIPS__: false,
'process.env.CLERK_ENV': JSON.stringify('production'),
'process.env.NODE_ENV': JSON.stringify('production'),
},
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Align compile-time constants to a single primitive type

__BUILD_DISABLE_RHC__ is injected as the string "false" whereas the neighbouring flags are injected as booleans.
If downstream code does if (__BUILD_DISABLE_RHC__) the branch behaviour will differ from the others.

-      __BUILD_DISABLE_RHC__: JSON.stringify('false'),
+      __BUILD_DISABLE_RHC__: false,

Double-check any code paths that expect a string before applying.


🏁 Script executed:

#!/bin/bash
rg "__BUILD_DISABLE_RHC__" -n -C2

Length of output: 5820


Align __BUILD_DISABLE_RHC__ to a boolean primitive

The __BUILD_DISABLE_RHC__ flag is currently injected as a string literal (“false”) but used in boolean contexts—causing "false" to be truthy at runtime. Let’s switch it to a real boolean and keep your type defs in sync:

• In packages/clerk-js/rslib.config.ts

    define: {
@@
-     __BUILD_DISABLE_RHC__: JSON.stringify('false'),
+     __BUILD_DISABLE_RHC__: false,
    },

• In packages/clerk-js/src/global.d.ts

- declare const __BUILD_DISABLE_RHC__: string;
+ declare const __BUILD_DISABLE_RHC__: boolean;

• Also update other bundler configs for consistency:
– packages/clerk-js/rspack.config.js
– packages/chrome-extension/tsup.config.ts

Double-check that no code path relies on a string value before landing these changes.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
define: {
__DEV__: false,
__PKG_NAME__: JSON.stringify(packageJSON.name),
__PKG_VERSION__: JSON.stringify(packageJSON.version),
__BUILD_FLAG_KEYLESS_UI__: false,
__BUILD_DISABLE_RHC__: JSON.stringify('false'),
__BUILD_VARIANT_CHIPS__: false,
'process.env.CLERK_ENV': JSON.stringify('production'),
'process.env.NODE_ENV': JSON.stringify('production'),
},
// packages/clerk-js/rslib.config.ts
define: {
__DEV__: false,
__PKG_NAME__: JSON.stringify(packageJSON.name),
__PKG_VERSION__: JSON.stringify(packageJSON.version),
__BUILD_FLAG_KEYLESS_UI__: false,
- __BUILD_DISABLE_RHC__: JSON.stringify('false'),
+ __BUILD_DISABLE_RHC__: false,
__BUILD_VARIANT_CHIPS__: false,
'process.env.CLERK_ENV': JSON.stringify('production'),
'process.env.NODE_ENV': JSON.stringify('production'),
},
🤖 Prompt for AI Agents
In packages/clerk-js/rslib.config.ts lines 12 to 21, the __BUILD_DISABLE_RHC__
flag is set as a string "false" but used as a boolean, causing incorrect
truthiness. Change its value to the boolean false instead of a string. Also
update the corresponding type definitions in packages/clerk-js/src/global.d.ts
and ensure the same boolean usage is reflected in other bundler configs like
packages/clerk-js/rspack.config.js and packages/chrome-extension/tsup.config.ts.
Verify no code depends on the string form before applying these changes.

@dstaley
Copy link
Member Author

dstaley commented Aug 4, 2025

The ESM bundle being emitted seems well formed, but I think we might have some circular dependency issues. Vite's dev server has issues resolving BaseResource, and Vite Rolldown's dev/prod server has issues with the Browser Tabs lock package. Putting on hold for now until I get more time to investigate.

@clerk-cookie
Copy link
Collaborator

Hello 👋

We currently close PRs after 60 days of inactivity. It's been 50 days since the last update here. If we missed this PR, please reply here. Otherwise, we'll close this PR in 10 days.

Thanks for being a part of the Clerk community! 🙏

@clerk-cookie
Copy link
Collaborator

Hello 👋

We currently close PRs after 60 days of inactivity. It's been 50 days since the last update here. If we missed this PR, please reply here. Otherwise, we'll close this PR in 10 days.

Thanks for being a part of the Clerk community! 🙏

@clerk-cookie clerk-cookie added Stale and removed Stale labels Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants