Sibling ForEach blocks with the same IDs share Compose keys since #533

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

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
22/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
android, kotlin, swift
領域
mobile

調査の方向性

The bug is in how unrolled ForEach content gets Compose keys, so start from the key computation that uses currentCompositeKeyHash and the ForEach identity namespace, and from the rememberSaveable path that restores state under that key. Reproduce with two sibling ForEach blocks that share IDs, then check whether two Row(id: 1) views end up with the same key. Done means siblings get distinct keys and the TabView re-entry case still keeps its state. Pick the discriminator with a maintainer first, since the reporter's approach is still open.

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

説明

Since #533, unrolled ForEach content is keyed by identity alone. That fixed the TabView remount, but two sibling ForEach blocks with the same IDs now get the same Compose keys:

struct Row: View {
    let list: String
    let id: Int
    @State var taps = 0
    var body: some View {
        Text("\(list) \(id): \(taps)").onTapGesture { taps += 1 }
    }
}

VStack {
    ForEach([1, 2], id: \.self) { Row(list: "favorites", id: $0) }
    ForEach([1, 2, 3], id: \.self) { Row(list: "all", id: $0) }
}

Both Row(id: 1) views get the same currentCompositeKeyHash, so rememberSaveable restores them under one key and a row can take the other block's state. In a Skip Fuse app (favorites and recents of the same items in one LazyVStack), this trapped in syncState on a null StateSupport after scrolling, on an Android 16 emulator with skip-ui 1.62.0.

Keying by (ForEachIdentityNamespace, identity), as before #533, separates siblings, but the namespace is remembered, so it changes on re-entry, which is the TabView case. A discriminator that survives re-entry, such as the ForEach's position among its parent's children combined with the identity, would fix both. Happy to open a PR once you've picked an approach.

Found with Claude Code while porting a SwiftUI app to Android with Skip Fuse.

主要言語
Swift
スター
332
フォーク
91
平均マージ
4日 9時間
マージ済み PR(30日)
10

環境構築

はじめの一歩

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

skiptools/skip-ui のほかの issue

skiptools/skip-ui の issue をすべて見る

似ている issue

Swift の issue をもっと見る

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

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