Demo: fix the @Entry closure warning for showAPIConfiguration

オープン
#481 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
11

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

MacPaw/OpenAI のほかの issue

MacPaw/OpenAI の issue をすべて見る

似ている issue

Swift の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。