Skip to content

Commit 92476b0

Browse files
committed
Feedback
1 parent f4b9897 commit 92476b0

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/Components/Components/src/IPersistentComponentStateSerializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ internal interface IPersistentComponentStateSerializer
99
{
1010
void Persist(Type type, object value, IBufferWriter<byte> writer);
1111
object Restore(Type type, ReadOnlySequence<byte> data);
12-
}
12+
}

src/Components/Components/src/PersistentState/PersistentValueProviderComponentSubscription.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal partial class PersistentValueProviderComponentSubscription : IDisposabl
3030
private readonly RestoringComponentStateSubscription? _restoringSubscription;
3131
private object? _lastValue = _uninitializedValue;
3232
private bool _hasPendingInitialValue;
33-
private bool _ignoreUpdatedValues;
33+
private bool _ignoreComponentPropertyValue;
3434
private string? _storageKey;
3535

3636
public PersistentValueProviderComponentSubscription(
@@ -59,6 +59,12 @@ public PersistentValueProviderComponentSubscription(
5959
new RestoreOptions { RestoreBehavior = attribute.RestoreBehavior, AllowUpdates = attribute.AllowUpdates });
6060
}
6161

62+
// GetOrComputeLastValue is a bit of a special provider.
63+
// Right after a Restore operation it will capture the last value and return that, but it must support the user
64+
// overriding the property at a later point, so to support that, we need to keep track of whether or not we have
65+
// delivered the last value, and if so, instead of returning the _lastValue, we simply read the property and return
66+
// that instead. That way, if the component updates the property in SetParametersAsync, we won't revert it to the
67+
// value we restored from the persistent state.
6268
internal object? GetOrComputeLastValue()
6369
{
6470
var isInitialized = !ReferenceEquals(_lastValue, _uninitializedValue);
@@ -74,12 +80,12 @@ public PersistentValueProviderComponentSubscription(
7480
}
7581
else
7682
{
77-
if (_ignoreUpdatedValues)
83+
if (_ignoreComponentPropertyValue)
7884
{
7985
// At this point, we just received a value update from `RestoreProperty`.
8086
// The property value might have been modified by the component and in this
8187
// case we want to overwrite it with the value we just restored.
82-
_ignoreUpdatedValues = false;
88+
_ignoreComponentPropertyValue = false;
8389
return _lastValue;
8490
}
8591
else
@@ -124,7 +130,7 @@ internal void RestoreProperty()
124130
_lastValue = _customSerializer.Restore(_propertyType, sequence);
125131
if (!skipNotifications)
126132
{
127-
_ignoreUpdatedValues = true;
133+
_ignoreComponentPropertyValue = true;
128134
_subscriber.NotifyCascadingValueChanged(ParameterViewLifetime.Unbound);
129135
}
130136
}
@@ -141,7 +147,7 @@ internal void RestoreProperty()
141147
_lastValue = value;
142148
if (!skipNotifications)
143149
{
144-
_ignoreUpdatedValues = true;
150+
_ignoreComponentPropertyValue = true;
145151
_subscriber.NotifyCascadingValueChanged(ParameterViewLifetime.Unbound);
146152
}
147153
}

0 commit comments

Comments
 (0)