Template `MainActivity` strands Compose dialog saved state on every process death, leading to `TransactionTooLargeException` when leaving the app
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Start with the MainActivity.setContent template in SkipProject.swift around lines 3690–3693 and trace how its saveable state interacts with dialogs and activity restoration. The issue describes a Kotlin onCreate workaround that removes SaveableStateRegistry:Dialog: entries before super.onCreate; compare that approach with preserving root state. Done means repeated process deaths with a dialog open no longer grow the saved-state bundle, while sheets still open, close, and reopen normally.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Every time Android ends a Skip app's process in the background while a sheet, alert or other Compose dialog is open, that dialog's saved state is left in the activity's saved-state bundle for good. The entries pile up across process deaths until the bundle passes Android's ~500 KB binder limit, and the next time the user leaves the app it crashes:
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 513868 bytes
at android.app.servertransaction.ActivityClient.activityStopped(...)
We hit this in production on a Galaxy S24 Ultra (Android 17). The crash bundle held 9 SaveableStateRegistry:Dialog:<uuid> entries of about 60 KB each. After the crash Android drops the saved state, so it is one crash per build-up rather than a loop.
Minimal reproduction: a fresh skip init app
Skip 1.9.16, skip init --native-app --appid=dev.example.sheetrepro sheet-repro SheetRepro, Main.kt untouched. The only change is one sheet on the Welcome tab:
@State var showSheet = false
// in the VStack:
Button("Show sheet") { showSheet = true }
// on the VStack:
.sheet(isPresented: $showSheet) { Text("Sheet content") }
On an API 37 emulator, repeat:
- Tap "Show sheet".
- Press Home.
adb shell am kill dev.example.sheetrepro(what the system does to a backgrounded process).- Relaunch from the launcher. The sheet is not shown again, which is expected.
After step 2, read mIcicle=Bundle[mParcelledData.dataSize=…] for the app's activity in adb shell dumpsys activity activities:
| Cycle | Template Main.kt |
With the workaround below |
|---|---|---|
| No sheet ever opened | 2,088 bytes | 2,088 bytes |
| 1 | 3,728 bytes | 3,728 bytes |
| 2 | 5,368 bytes | 3,728 bytes |
| 3 | 7,008 bytes | 3,728 bytes |
| 8 | 15,208 bytes | 3,728 bytes |
With the template, each kill with the sheet open adds 1,640 bytes and nothing ever removes them. With the workaround, each relaunch logs one stranded entry with a new id every time, for example [SaveableStateRegistry:Dialog:821f8606-3898-470d-a992-4f03c7713451], then [SaveableStateRegistry:Dialog:8558bb08-…].
A one-line sheet strands little, so this app would need about 300 kills to crash. A sheet with real content strands far more: in our app a small form sheet added 15,504 bytes per kill and crashed at cycle 33 (513,868 bytes, 33 × SaveableStateRegistry:Dialog:<uuid>, the trace above), and the production crash got there in 9.
Why
- The template's
MainActivity.setContentwraps the root inrememberSaveableStateHolder()/SaveableStateProvider(true)and callsSideEffect { saveableStateHolder.removeState(true) }(SkipProject.swift).removeStatetakes the root registry out of whatSaveableStateHolderImplsaves (checked in Compose runtime-saveable 1.11.2), so norememberSaveablevalue in the root composition is ever saved. - A Compose dialog window keeps its id in a
rememberSaveablein the parent composition and registers its own content state with the activity'sSavedStateRegistryunderSaveableStateRegistry:Dialog:<id>. SkipUI's sheets areModalBottomSheet, which is what both runs used; its date picker usesBasicAlertDialog. - So after any recreation the dialog's id is new (the new id on every relaunch above shows this), and its old entry can never be claimed. AndroidX savedstate (1.4.0) copies every unclaimed restored entry into each later save, so the entries are carried forward indefinitely.
Workaround we shipped
Remove the stranded entries before super.onCreate restores them. Nothing is lost, because no dialog can ever claim them:
override fun onCreate(savedInstanceState: android.os.Bundle?) {
removeStrandedDialogState(savedInstanceState)
super.onCreate(savedInstanceState)
// ...
}
private fun removeStrandedDialogState(savedInstanceState: android.os.Bundle?) {
val registryState = savedInstanceState?.getBundle("androidx.lifecycle.BundlableSavedStateRegistry.key") ?: return
registryState.keySet()
.filter { it.startsWith("SaveableStateRegistry:Dialog:") }
.forEach { registryState.remove(it) }
}
In our app it held the saved state steady (17,592 bytes with the sheet open) over 28 kills with no crash, and sheets still open, close and reopen normally. It depends on two key strings that AndroidX and Compose don't make public, so a fix in the template or in SkipUI would be better than every app carrying it. One option is for the template to do the removal above; another is to save the root state rather than discard it, though I don't know why removeState(true) is there.
Not covered: I did not run the fresh app to the crash itself, only the steady growth; the crash is from our app and production. There is no automated test; the evidence is the emulator measurements above.
- Ngôn ngữ chính
- Swift
- Star
- 3.3k
- Fork
- 114
- Merge trung bình
- 2 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 6
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của skiptools/skip
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Comments in functionsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
enhancement project
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
skiptools/skip#673 · 1 reaction ·
Maintainer thường phản hồi trong vòng 2 ngày
-
documentation
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 2 ngày
-
documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của skiptools/skip
Issue tương tự
-
AndroidAssetManager(env:peer:) in AssetURLProtocol.swift doesn't compile for Android on the Swift nightlyCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
erkamyaman/unslop-anything#579 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
erkamyaman/rust-anything#1311 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Android: a long press's `contextmenu` event carries no point (`clientX` and `clientY` are 0)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug priority:low status:queued
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày