-
Notifications
You must be signed in to change notification settings - Fork 437
fix(clerk-js): Revert query filtering from fapiClient #6817
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -105,20 +105,7 @@ export function createFapiClient(options: FapiClientOptions): FapiClient { | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| function buildQueryString({ method, path, sessionId, search, rotatingTokenNonce }: FapiRequestInit): string { | ||||||||||||||||||
| const filteredSearch = | ||||||||||||||||||
| search && typeof search === 'object' | ||||||||||||||||||
| ? Object.keys(search as Record<string, any>).reduce( | ||||||||||||||||||
| (acc, key) => { | ||||||||||||||||||
| const value = (search as Record<string, any>)[key]; | ||||||||||||||||||
| if (value !== undefined) { | ||||||||||||||||||
| acc[key] = value; | ||||||||||||||||||
| } | ||||||||||||||||||
| return acc; | ||||||||||||||||||
| }, | ||||||||||||||||||
| {} as Record<string, any>, | ||||||||||||||||||
| ) | ||||||||||||||||||
| : search; | ||||||||||||||||||
| const searchParams = new URLSearchParams(filteredSearch as any); | ||||||||||||||||||
| 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 | ||||||||||||||||||
|
Comment on lines
+108
to
109
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainPotential 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 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 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| // Append supported FAPI version to the query string | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing changeset content.
The changeset file is empty and should include package names and descriptions of changes.
A valid changeset should follow this format:
📝 Committable suggestion
🤖 Prompt for AI Agents