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

Đang mở Phù hợp với người mới
#381 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
kotlin, swift
Lĩnh vực
mobile

Hướng nghiên cứu

Bắt đầu với WidgetServerSettingsStore.kt và WidgetScope.kt trên Android: xác nhận rằng widgetKey/storageKey khác nhau đối với WidgetScope.Instance, sau đó điều chỉnh lớp cài đặt widget để đọc qua WidgetScope.of(scope.widgetId). Thêm bài test Robolectric từ issue dưới packages/android-client/android/src/test/java/voltra/widget/server/ và chạy lệnh test Gradle đã cho. Sau đó phản chiếu thay đổi trong đường dẫn iOS WidgetWidgetServerSettingsLayer.settings(for:) và kiểm tra các test store hiện có; hoàn tất nghĩa là một instance kế thừa URL, interval, method, headers và body của widget của nó trong khi ETag/status/props vẫn theo từng instance.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
864
Fork
51
Merge trung bình
2 ngày 2 giờ
Pull request đã merge (30 ngày)
10

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của callstackincubator/voltra

Tất cả issue của callstackincubator/voltra

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.