Anyone had an issue with `stringResource` when usi...
# compose
s
Anyone had an issue with
stringResource
when using the formatArgs? For example
stringResource(Res.string.mystring, param1, param2)
. Sometimes it will return a previous instance of it, not with the new value of
param1
. Tested on the latest
v1.6.0-rc01
but still present. Looking at the source code I don't even understand how it works:
Copy code
fun stringResource(resource: StringResource, vararg formatArgs: Any): String {
    val resourceReader = LocalResourceReader.current
    val args = formatArgs.map { it.toString() }
    val str by rememberResourceState(resource, { "" }) { env ->
        loadString(resource, args, resourceReader, env)
    }
    return str
}
the "args" are only used within the remember, and this line is not called when I have the bug in my case.
j
Looks like a bug to me. I think should be:
val args = remember(formatArgs) {
formatArgs.map ...
}
However I am not entirely sure. Is your params dynamic and shifts value, like from an uiState or such?
s
My params are regular
String
, coming from a list of items… But I really don't get why sometimes it works, sometimes it does not. And of course I'm not able to reproduce it within a smaller project to open an official bug on the bug tracker.
j
If its a list I think because lists are unstable in compose. Depends when compose trigger new recompositions.
l
Did you open an issue on GitHub about that? It looks like an implementation bug to me.
s
@louiscad I did not, I was looking if someone had an idea why this was the case. But yes, I will do it now.
@louiscad, thanks for pushing me to open the issue, it was indeed a bug. https://github.com/JetBrains/compose-multiplatform/pull/4333
👍 1
l
Fun thing is that @zsmb and @Sebastian Aigner encountered it in their last stream as well, and found the exact same remember without the right key mistake.
z
I spent about 15 minutes yesterday creating a clean sample and nice description for the issue too, then as I went to link the source code where the key was missing, I was surprised to see that it's no longer missing, and the file was updated 3 hours prior 😀
l
Nice thing is they added a test for that, and that's a good example if you want to submit failing tests for any future bugs (I don't hope for those though)
103 Views