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

オープン 初心者向け
#381 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
kotlin, swift
領域
mobile

調査の方向性

Android では WidgetServerSettingsStore.kt と WidgetScope.kt から始めます。widgetKey/storageKey が WidgetScope.Instance で異なることを確認し、その後 widget settings layer が WidgetScope.of(scope.widgetId) で読み取るように調整します。issue にある Robolectric テストを packages/android-client/android/src/test/java/voltra/widget/server/ 配下に追加し、示された Gradle テストコマンドを実行します。次に iOS の WidgetWidgetServerSettingsLayer.settings(for:) パスに変更をミラーし、既存の store テストを確認します。完了とは、インスタンスが自身の widget の URL、interval、method、headers、body を継承し、ETag/status/props はインスタンスごとに残ることを意味します。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
864
フォーク
51
平均マージ
2日 2時間
マージ済み PR(30日)
10

環境構築

はじめの一歩

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

callstackincubator/voltra のほかの issue

callstackincubator/voltra の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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