dotvvm icon indicating copy to clipboard operation
dotvvm copied to clipboard

Caching of bindings that access localized strings

Open cafour opened this issue 2 years ago • 3 comments
trafficstars

Model scenario: A website has a value binding that looks like {value: Resources.SomeLocalizedMessage}. The current culture is set to the culture of the user.

Expected: A correctly localized message is shown.

Actual: The variant that was first accessed by the binding is shown.

Note: Reported by the OPR0087 people.

cafour avatar Jan 23 '23 13:01 cafour

This is problematic to "fix", the actual expected behavior IMHO is exception "Cannot translate Resources.SomeLocalizedMessage to JavaScript". The problem is that we currently translate static getters as "constants", which is convenient when the getter is pure (as it should be), but leads to weird behavior otherwise.

We aren't going to recompile all JS expressions on every request, and I'm not sure we can disallow using those static properties (I have no idea how people use it). I'm not sure what else can we do. Maybe replace all these getters with a CodeSymbolicParameter which will get evaluated every time, but I think we consider ParametrizedCode.ToString(f) pure in all places, so this is also asking for problems.

exyi avatar Jan 26 '23 10:01 exyi

Could we add culture to the cache key in case the binding uses properties on resources? This may be quite a common scenario - I've seen a lot of bindings like this:

<dialog ...>
    <h1>{value: IsNewItem ? Resources.NewItemDialogTitle : Resources.EditItemDialogTitle}</h1>
    ....
</dialog>

Since the dialog can appear multiple times in different modes, the resource binding cannot be used.

tomasherceg avatar Jan 26 '23 11:01 tomasherceg

Could we add culture to the cache key in case the binding uses properties on resources?

That would probably require recompiling the entire view for each culture, after view compilations the bindings are set directly into the controls and the compiled javascript is a direct property of the binding.

exyi avatar Jan 26 '23 11:01 exyi