Skip to content

Commit 7dbdea2

Browse files
committed
fix missing serializer for empty NavigationResult
1 parent 46e560a commit 7dbdea2

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ Change Log
99
### Codegen
1010

1111

12-
## 0.34.2 *(2025-11-13)*
12+
## 0.34.3 *(2025-11-19)*
13+
14+
- Fix crash when serializing empty `NavigationResult` instances.
15+
16+
17+
## 0.34.2 *(2025-11-17)*
1318

1419
- Resolve issues when using the navigation result APIs in Android host side tests, which had failures
1520
because of `Bundle` APIs being called but them not being mocked.

navigation/src/androidMain/kotlin/com/freeletics/khonshu/navigation/NavigationResults.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,17 @@ public class NavigationResultRequest<R> @InternalNavigationTestingApi constructo
7777
) {
7878
private val serializer = NavigationResult.serializer(resultSerializer)
7979

80-
private val emptyValue = NavigationResult(null)
81-
8280
/**
8381
* Emits any result that was passed to [deliverNavigationResult] with the matching [key].
8482
*
8583
* Results will only be delivered to one collector at a time.
8684
*/
8785
public val results: Flow<R>
88-
get() = state.getStateFlow(key.requestKey, emptyValue, serializer)
86+
get() = state.getStateFlow<NavigationResult<R>>(key.requestKey, NavigationResult(null), serializer)
8987
.mapNotNull {
9088
if (it.value != null) {
91-
state[key.requestKey] = emptyValue
92-
it.value
89+
state[key.requestKey] = NavigationResult(null)
90+
it.value as R
9391
} else {
9492
null
9593
}

navigation/src/androidMain/kotlin/com/freeletics/khonshu/navigation/internal/StackEntryState.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
1414
import kotlinx.coroutines.flow.StateFlow
1515
import kotlinx.coroutines.flow.asStateFlow
1616
import kotlinx.serialization.DeserializationStrategy
17+
import kotlinx.serialization.KSerializer
1718
import kotlinx.serialization.SerializationStrategy
1819
import kotlinx.serialization.serializer
1920

@@ -35,15 +36,15 @@ public class StackEntryState(initialState: Map<String, Any?>) {
3536
public fun <T : Any> getStateFlow(
3637
key: String,
3738
initialValue: T,
38-
strategy: DeserializationStrategy<T>?,
39+
strategy: KSerializer<T>?,
3940
): StateFlow<T> {
4041
// If a flow exists we should just return it, and since it is a StateFlow and a value must
4142
// always be set, we know a value must already be available
4243
val flow = flows.getOrPut(key) {
4344
// If there is not a value associated with the key, add the initial value,
4445
// otherwise, use the one we already have.
4546
val initial = if (key !in values) {
46-
values[key] = initialValue
47+
set(key, initialValue, strategy)
4748
initialValue
4849
} else {
4950
get(key, strategy)

0 commit comments

Comments
 (0)