You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Provide a way to set conditional [SkipOutput] attribute based on changes.
Usecase:
Element has on:change event that uses dispatch global
Multiple components, including the one sendind dispatch, are subscribed to an event
When event happens, some components need to be updated.
Because the caller also receives the event, it also gets re-rendered. And it changes the Element that has on:change event, which again causes dispatch.
So I need to break the cycle by using SkipOutput when receiving component is not updated.
There is currently a workaround that disposes produced html, but it is not ideal. See below.
[SkipOutput]
public async Task UpdateEnum(int selectedValue)
{
if (BaseEnum.SelectedValue != selectedValue)
{
// dispatch global event, but this component is also subscribed to it.
DispatchGlobal(new DependentEnumChangedEvent(BaseEnumName, selectedValue));
}
}
public async Task Handle(DependentEnumChangedEvent data)
{
if (ParentEnumName == data.EnumName)
{
// some logic that needs re-render
}
else
{
// also the current component is registered to DispatchGlobal, but I do not want it to re-render as it causes on:change event to fire again and makes infinite loop of dispatches
_httpContextAccessor.HttpContext!.Response.Headers.TryAdd("Hydro-Skip-Output", "True");
}
}
cshtml
<select id="@Model.BaseEnumName" name="@Model.BaseEnumName" on:change="@(() => Model.UpdateEnum(Param.JS<int>(getValueScript)))">
<option value="">@T["Please select a value"]</option>
@foreach(var value in items){
<option value="@value.Value" selected="@value.Selected">@value.Text</option>
}
</select>
Maybe there is some error in my understanding of lifecycle, so feel free to tell me
Activity
kjeske commentedon Jun 9, 2025
Good point, it should be possible to skip the output by calling some method inside your action/handler. Something like:
Shouldn't be hard to implement. Will definitely add it soon.
Thanks for a good idea!