Demo: fix the @Entry closure warning for showAPIConfiguration

未关闭
#481 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
70/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
swift
领域
frontend

调研方向

Start by reading Demo/DemoChat/Sources/UI/Environment/APIConfiguration.swift, then inspect how Demo/App/DemoApp.swift sets showAPIConfiguration and how Demo/DemoChat/Sources/UI/Misc/MiscView.swift uses it. Build Demo to check the warning; done when it is gone and the API Configuration button still opens the screen.

由索引模型根据 Issue 内容生成。

描述

Building Demo reports this warning:

Demo/DemoChat/Sources/UI/Environment/APIConfiguration.swift:13:45: warning: Storing a closure in '@Entry var showAPIConfiguration' may invalidate dependents on every update because closures may not be comparable. (from macro 'Entry ')

Context

EnvironmentValues.showAPIConfiguration is a () -> Void that opens the API Configuration screen.

  • DemoApp sets it with .environment(\.showAPIConfiguration, { isShowingAPIConfigModal = true }) in its body (Demo/App/DemoApp.swift).
  • MiscView reads it for its API Configuration button (Demo/DemoChat/Sources/UI/Misc/MiscView.swift).

SwiftUI can't compare closures, so it can't tell that the value is unchanged. A new closure is created each time DemoApp.body runs, so every run counts as a change and re-evaluates the views that read the value, here MiscView. The cost is small in this app. The warning is only in the Demo build; it doesn't reach users of the package.

The same warning was reported for dateProviderValue and idProviderValue. Nothing ever set those, so they were removed.

Options

  • Store a type with a stable identity instead of a bare closure, e.g. a final class that holds the action, so the environment value compares by identity. A plain struct wrapper would only silence the warning.
  • Stop using the environment for this: pass the action to MiscView through the views in between, or give it a binding to isShowingAPIConfigModal.

Done when the Demo build no longer reports the warning and the API Configuration button still opens the screen.

主要语言
Swift
星标
2.9k
派生
519
平均合并
3 天 12 小时
30 天内合并 PR
11

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

MacPaw/OpenAI 的其他 Issue

查看 MacPaw/OpenAI 的全部 Issue

相似的 Issue

更多 Swift Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。