@@ -1398,17 +1398,37 @@ def reset(self):
13981398 for substate in self .substates .values ():
13991399 substate .reset ()
14001400
1401+ @classmethod
1402+ @functools .lru_cache
1403+ def _is_client_storage (cls , prop_name_or_field : str | ModelField ) -> bool :
1404+ """Check if the var is a client storage var.
1405+
1406+ Args:
1407+ prop_name_or_field: The name of the var or the field itself.
1408+
1409+ Returns:
1410+ Whether the var is a client storage var.
1411+ """
1412+ if isinstance (prop_name_or_field , str ):
1413+ field = cls .get_fields ().get (prop_name_or_field )
1414+ else :
1415+ field = prop_name_or_field
1416+ return field is not None and (
1417+ isinstance (field .default , ClientStorageBase )
1418+ or (
1419+ isinstance (field .type_ , type )
1420+ and issubclass (field .type_ , ClientStorageBase )
1421+ )
1422+ )
1423+
14011424 def _reset_client_storage (self ):
14021425 """Reset client storage base vars to their default values."""
14031426 # Client-side storage is reset during hydrate so that clearing cookies
14041427 # on the browser also resets the values on the backend.
14051428 fields = self .get_fields ()
14061429 for prop_name in self .base_vars :
14071430 field = fields [prop_name ]
1408- if isinstance (field .default , ClientStorageBase ) or (
1409- isinstance (field .type_ , type )
1410- and issubclass (field .type_ , ClientStorageBase )
1411- ):
1431+ if self ._is_client_storage (field ):
14121432 setattr (self , prop_name , copy .deepcopy (field .default ))
14131433
14141434 # Recursively reset the substate client storage.
@@ -2360,8 +2380,9 @@ async def update_vars_internal(self, vars: dict[str, Any]) -> None:
23602380 for var , value in vars .items ():
23612381 state_name , _ , var_name = var .rpartition ("." )
23622382 var_state_cls = State .get_class_substate (state_name )
2363- var_state = await self .get_state (var_state_cls )
2364- setattr (var_state , var_name , value )
2383+ if var_state_cls ._is_client_storage (var_name ):
2384+ var_state = await self .get_state (var_state_cls )
2385+ setattr (var_state , var_name , value )
23652386
23662387
23672388class OnLoadInternalState (State ):
0 commit comments