Commit 6bd3aa5
committed
fix(compose): retain root span cache entries synchronously to avoid a dispose/remember race
Retaining inside a DisposableEffect deferred the retain to the
effect-application phase, but Compose dispatches an outgoing
composable's onDispose before an incoming composable's
DisposableEffect in the same recomposition. Replacing a SentryTraced
call under a given scopes (e.g. during navigation) could therefore
have the outgoing call's release clear the cache before the incoming
call's retain ran, so a later SentryTraced call under the same scopes
found nothing cached and created a duplicate root span.
Retain now happens inside remember instead, which runs synchronously
during composition, before any effect-phase work for that frame -
including another SentryTraced call's dispose. Release stays in
DisposableEffect's onDispose since its timing no longer matters.
Adds a regression test that swaps which keyed SentryTraced composable
is mounted under the same scopes twice in a row, which reproduces the
duplicate span without this fix.1 parent 6702434 commit 6bd3aa5
2 files changed
Lines changed: 37 additions & 4 deletions
File tree
- sentry-compose/src
- androidMain/kotlin/io/sentry/compose
- androidUnitTest/kotlin/io/sentry/compose
Lines changed: 7 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
131 | 134 | | |
132 | 135 | | |
133 | 136 | | |
| |||
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
8 | 12 | | |
9 | 13 | | |
10 | 14 | | |
| |||
117 | 121 | | |
118 | 122 | | |
119 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
120 | 150 | | |
0 commit comments