fix(clerk-js): Revert query filtering from fapiClient#6817
fix(clerk-js): Revert query filtering from fapiClient#6817panteliselef wants to merge 1 commit intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 3ac30a2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds a changeset metadata file. Updates Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant fapiClient
participant URLSearchParams as URLSearchParams
participant Normalizer as Later Normalization
Caller->>fapiClient: request(search)
Note right of fapiClient: search may include undefined and comma-delimited values
fapiClient->>URLSearchParams: construct directly from search
URLSearchParams-->>fapiClient: query params
Note over fapiClient: Augment query (API/JS versions, nonce, domain, _method, session id)
fapiClient-->>Caller: prepared request with query
Caller->>Normalizer: parse response/query values
Note over Normalizer: Convert comma-delimited strings back to arrays
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Comment |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
.changeset/blue-oranges-make.md(1 hunks)packages/clerk-js/src/core/fapiClient.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/src/core/fapiClient.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/src/core/fapiClient.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/src/core/fapiClient.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/src/core/fapiClient.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
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor 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
Useconst assertionsfor literal types:as const
Usesatisfiesoperator 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 ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor 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/src/core/fapiClient.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/src/core/fapiClient.ts
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/blue-oranges-make.md
⏰ 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). (27)
- GitHub Check: Integration Tests (expo-web, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (custom, chrome)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (tanstack-react-router, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 14)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (machine, chrome)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (tanstack-react-start, chrome)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (elements, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Integration Tests (quickstart, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Publish with pkg-pr-new
- GitHub Check: Static analysis
- GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
- GitHub Check: Unit Tests (22, **)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
| --- | ||
| --- |
There was a problem hiding this comment.
Missing changeset content.
The changeset file is empty and should include package names and descriptions of changes.
A valid changeset should follow this format:
---
+"@clerk/clerk-js": patch
---
+
+Revert query filtering from fapiClient - no longer filter undefined properties before building query parameters.📝 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.
| --- | |
| --- | |
| --- | |
| "@clerk/clerk-js": patch | |
| --- | |
| Revert query filtering from fapiClient - no longer filter undefined properties before building query parameters. |
🤖 Prompt for AI Agents
In .changeset/blue-oranges-make.md around lines 1 to 2, the changeset file is
empty; replace the placeholder with a valid changeset YAML block that lists the
affected package(s) and a short summary of the change(s). Specifically, add the
top-level version bump type for each package (patch/minor/major) as keys and a
brief human-readable description under the body (wrap text as needed), following
the standard Changesets format: a header mapping package names to release types,
a divider line of "---", and then the description paragraph(s).
| const searchParams = new URLSearchParams(search as any); | ||
| // the above will parse {key: ['val1','val2']} as key: 'val1,val2' and we need to recreate the array bellow |
There was a problem hiding this comment.
🧩 Analysis chain
Potential issue with undefined values in URLSearchParams.
The URLSearchParams constructor will stringify undefined values as "undefined" strings rather than omitting them, which could result in query parameters like ?param=undefined being sent to the API.
Run this script to check how undefined values are handled across the codebase:
Consider filtering undefined values before passing to URLSearchParams:
function buildQueryString({ method, path, sessionId, search, rotatingTokenNonce }: FapiRequestInit): string {
- const searchParams = new URLSearchParams(search as any);
+ // Filter out undefined values to prevent them from being stringified as "undefined"
+ const filteredSearch = search && typeof search === 'object' && !Array.isArray(search)
+ ? Object.fromEntries(Object.entries(search).filter(([_, v]) => v !== undefined))
+ : search;
+ const searchParams = new URLSearchParams(filteredSearch as any);
// the above will parse {key: ['val1','val2']} as key: 'val1,val2' and we need to recreate the array bellow🏁 Script executed:
#!/bin/bash
# Description: Check how search parameters are constructed and used throughout the codebase
# Find places where search parameters are constructed or passed to fapiClient
rg -nP -C3 --type=ts --type=js 'search\s*:\s*[^,}]+' | head -20
# Look for undefined handling in query construction
ast-grep --pattern $'buildQueryString($_)'
# Check for any existing undefined filtering patterns
rg -nP 'undefined.*filter|filter.*undefined' --type=ts --type=jsLength of output: 2436
Filter out undefined search params before instantiating URLSearchParams
The URLSearchParams constructor stringifies undefined to "undefined", which will produce queries like ?param=undefined. In buildQueryString, add a step to remove undefined values before creating URLSearchParams:
function buildQueryString({ search, ... }: FapiRequestInit): string {
- const searchParams = new URLSearchParams(search as any);
+ const filteredSearch = Object.fromEntries(
+ Object.entries(search ?? {}).filter(([, v]) => v !== undefined)
+ );
+ const searchParams = new URLSearchParams(filteredSearch as any);
// …recreate array values below…📝 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.
| const searchParams = new URLSearchParams(search as any); | |
| // the above will parse {key: ['val1','val2']} as key: 'val1,val2' and we need to recreate the array bellow | |
| function buildQueryString({ search, ... }: FapiRequestInit): string { | |
| const filteredSearch = Object.fromEntries( | |
| Object.entries(search ?? {}).filter(([, v]) => v !== undefined) | |
| ); | |
| const searchParams = new URLSearchParams(filteredSearch as any); | |
| // the above will parse {key: ['val1','val2']} as key: 'val1,val2' and we need to recreate the array bellow |
🤖 Prompt for AI Agents
In packages/clerk-js/src/core/fapiClient.ts around lines 108-109, filter out
undefined values from the search object before creating URLSearchParams: iterate
keys of the search input, skip any key whose value is undefined, and for array
values create a new array with undefined entries removed (so arrays remain
arrays and not become "undefined" strings); then pass this cleaned object to new
URLSearchParams. Ensure you preserve non-array values and convert them to
strings only after removing undefined entries.
|
Closing in favour of #6819 as we decided to revert the previous PR all together. |
Description
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
Bug Fixes
Chores