Skip to content

Commit fc6a4d9

Browse files
Copilotjaviercn
andcommitted
Fix serializer cache to be instance-based to prevent cross-test contamination
- Changed _serializerCache from static to instance field to prevent different service providers from sharing cached serializers - This ensures each PersistentStateValueProvider instance has its own serializer cache Co-authored-by: javiercn <[email protected]>
1 parent d7ed4d9 commit fc6a4d9

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

src/Components/Components/src/PersistentStateValueProvider.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal sealed class PersistentStateValueProvider(PersistentComponentState stat
1919
{
2020
private static readonly ConcurrentDictionary<(string, string, string), byte[]> _keyCache = new();
2121
private static readonly ConcurrentDictionary<(Type, string), PropertyGetter> _propertyGetterCache = new();
22-
private static readonly ConcurrentDictionary<Type, IPersistentComponentStateSerializer?> _serializerCache = new();
22+
private readonly ConcurrentDictionary<Type, IPersistentComponentStateSerializer?> _serializerCache = new();
2323

2424
private readonly Dictionary<ComponentState, PersistingComponentStateSubscription> _subscriptions = [];
2525

@@ -101,17 +101,7 @@ private static PropertyGetter ResolvePropertyGetter(Type type, string propertyNa
101101

102102
private IPersistentComponentStateSerializer? ResolveSerializer(Type type)
103103
{
104-
if (_serializerCache.TryGetValue(type, out var cached))
105-
{
106-
return cached;
107-
}
108-
109-
var serializer = SerializerFactory(type);
110-
if (serializer != null)
111-
{
112-
_serializerCache.TryAdd(type, serializer);
113-
}
114-
return serializer;
104+
return _serializerCache.GetOrAdd(type, SerializerFactory);
115105
}
116106

117107
private IPersistentComponentStateSerializer? SerializerFactory(Type type)

0 commit comments

Comments
 (0)