Skip to content

fix: resolve mutable default argument in getAddressesForFid - #555

Open
dajiaohuang wants to merge 5 commits into
framesjs:mainfrom
dajiaohuang:fix/mutable-default-argument-getAddressesForFid
Open

fix: resolve mutable default argument in getAddressesForFid#555
dajiaohuang wants to merge 5 commits into
framesjs:mainfrom
dajiaohuang:fix/mutable-default-argument-getAddressesForFid

Conversation

@dajiaohuang

Copy link
Copy Markdown

Summary

修复 getAddressesForFid 函数中的可变默认参数问题。

问题

原代码使用了可变对象作为默认参数:

hubRequestOptions = {
  headers: {
    api_key: DEFAULT_HUB_API_KEY,
  },
},

这个默认对象在所有调用中共享,如果调用者修改了它,会影响后续调用。

Fix

  • 创建新的 requestOptions 对象,每次调用时都是 fresh 的
  • 正确合并用户提供的 hubRequestOptions 和默认的 api_key header

- Remove redundant else branch that was overwriting acc[type] with the same value
- Fix mutable default argument by creating requestOptions object fresh each time
- Properly merge user-provided hubRequestOptions with default api_key header
Create fresh requestOptions object each time to avoid shared mutable default.
Properly merge user-provided hubRequestOptions with default api_key header.
Create fresh requestOptions object each time to avoid shared mutable default.
Properly merge user-provided hubRequestOptions with default api_key header.
@vercel

vercel Bot commented Sep 2, 2026

Copy link
Copy Markdown

@dajiaohuang is attempting to deploy a commit to the Discove Team on Vercel.

A member of the Team first needs to authorize it.

@vercel vercel Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Additional Suggestion:

Missing !foundValue case in reduce condition means user data is never stored, so getUserDataForFid always returns all-undefined fields.

Fix on Vercel

...hubRequestOptions,
headers: {
...(hubRequestOptions.headers ?? {}),
api_key: DEFAULT_HUB_API_KEY,

@vercel vercel Bot Sep 2, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Header merge order forces DEFAULT_HUB_API_KEY to override a caller-supplied api_key, silently discarding custom hub credentials.

Fix on Vercel

@dajiaohuang

Copy link
Copy Markdown
Author

Addressed the current review feedback in the latest commit. The user-data reducer now stores the first value for each type and replaces it only when a newer timestamp is seen, so first-seen fields are no longer lost. Validation: git diff --check passed. The local checkout has no Yarn binary/dependencies, so the package test suite could not run here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant