Skip to content

fix: resolve mutable default argument in getAddressForFid - #554

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

fix: resolve mutable default argument in getAddressForFid#554
dajiaohuang wants to merge 4 commits into
framesjs:mainfrom
dajiaohuang:fix/mutable-default-argument-getAddressForFid

Conversation

@dajiaohuang

Copy link
Copy Markdown

Summary

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

问题

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

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.
@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:

Reducer only assigns acc[type] when a value already exists, so the first (and typically only) message per user data type is never stored, making getUserDataForFid return all-undefined fields.

Fix on Vercel

} = options;

const requestOptions = {
...hubRequestOptions,

@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.

Caller-supplied api_key header is silently overwritten by the hardcoded DEFAULT_HUB_API_KEY in getAddressForFid

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