mondeja / leptos-fluent

Internationalization framework for Leptos using Fluent
https://mondeja.github.io/leptos-fluent/
MIT License
38 stars 10 forks source link

Panics if `tr!` and `move_tr!` not inside reactive ownership tree #231

Closed mondeja closed 3 months ago

mondeja commented 3 months ago

The problem is that leptos-fluent macros tr! and move_tr! are based on a bug in Leptos v0.6 that has been solved on v0.7 (see https://github.com/leptos-rs/leptos/issues/2852), providing a false sense of security.

Currently we call expect_context inside tr! and move_tr!, but if these invocations are not located inside the reactive ownership tree, the call would panic. An example is provided in the previous example, calling them at on:click event.

The solution is to allow to pass an optional first i18n expr parameter to tr! and move_tr! to make a copy of the context and document this situation. Note that leptos_i18n doesn't have this problem because is always forcing the user to pass i18n context to t! macros.