Demo: fix the @Entry closure warning for showAPIConfiguration

Abierto
#481 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
70/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
swift
Área
frontend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Swift
Estrellas
2.9k
Forks
519
Merge medio
1 d 17 h
PR fusionados (30 d)
10

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de MacPaw/OpenAI

Todos los issues de MacPaw/OpenAI

Issues similares

Más issues de Swift

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.