Per-widget server settings are not read for instance scopes (widgets with configuration parameters)

Aperta Adatta ai principianti
#381 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
kotlin, swift
Ambito
mobile

Direzione di ricerca

Inizia su Android con WidgetServerSettingsStore.kt e WidgetScope.kt: conferma che widgetKey/storageKey divergono per WidgetScope.Instance, poi adegua il layer delle impostazioni del widget in modo che legga tramite WidgetScope.of(scope.widgetId). Aggiungi il test Robolectric dell'issue sotto packages/android-client/android/src/test/java/voltra/widget/server/ ed esegui il comando di test Gradle indicato. Poi replica la modifica nel percorso iOS WidgetWidgetServerSettingsLayer.settings(for:) e controlla i test dello store esistenti; fatto significa che un'istanza eredita URL, intervallo, metodo, header e body del suo widget mentre ETag/status/props restano per istanza.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Follow-up to #363. Found while reading the instance-scope code; confirmed on Android with a unit test, iOS from reading the code.

What happens

On main (b4b6e74), a widget that has configuration parameters resolves to WidgetScope.Instance. The per-widget settings layer then looks for settings under the instance's storage key (<widgetId>#<key>), but setWidgetServerUpdate with a widget id writes them under the widget id. So an instance does not see the URL, interval, method, headers or body set for its widget, and falls back to the global or config layers.

Expected

What WidgetScope and ADR 0007 say: "the settings layers keep resolving by widget id, so an instance inherits the widget's URL, interval, method, headers and body."

Cause

Android: the widget layer reads store.widgetKey(scope), and widgetKey uses scope.storageKey, which for an instance is "$widgetId#$key".

iOS has the same shape: WidgetWidgetServerSettingsLayer calls WidgetServerSettingsStore.settings(scope:), whose keychain account is built from scope.storageKey.

Repro (Android, Robolectric)

@RunWith(RobolectricTestRunner::class)
class WidgetSettingsInstanceScopeTest {
    private val url = "https://example.com/per-widget"

    @Test
    fun instanceScopeInheritsThePerWidgetSettingOfItsWidget() = runTest {
        val store = WidgetServerSettingsStore(RuntimeEnvironment.getApplication())
        store.set(WidgetServerUpdateSettings(url = url), WidgetScope.of("weather"))

        val resolved = WidgetWidgetServerSettingsLayer(store).settings(WidgetScope.Instance("weather", "k1"))

        assertEquals(url, resolved?.url)
    }
}

Placed in packages/android-client/android/src/test/java/voltra/widget/server/ and run with ./example/android/gradlew -p example/android :use-voltra_android-client:testDebugUnitTest --tests voltra.widget.server.WidgetSettingsInstanceScopeTest:

java.lang.AssertionError: expected:<https://example.com/per-widget> but was:<null>

The same test with WidgetScope.of("weather") on the read side passes.

Possible fix

Have the widget layer read by widget id on both platforms, e.g. on Android store.read(store.widgetKey(WidgetScope.of(scope.widgetId))) in WidgetWidgetServerSettingsLayer, and WidgetServerSettingsStore.settings(scope: .widget(id: scope.widgetId)) in WidgetWidgetServerSettingsLayer.settings(for:) on iOS. The ETag, status and props stores should keep using storageKey, since those are meant to be per instance.

Library version: 2.6.1 (main at b4b6e74). Not tied to a React Native, React or Expo version.

Lingua principale
TypeScript
Stelle
864
Fork
51
Merge medio
2g 2h
PR unite (30g)
10

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di callstackincubator/voltra

Tutte le issue di callstackincubator/voltra

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.