ColorPicker opens and immediately closes #858

Closed
opened 2026-01-29 17:45:25 +00:00 by claunia · 1 comment
Owner

Originally created by @OndrejUzovic on GitHub (May 29, 2023).

It seems there is a kind of race-condition in the toggle functionality of Popup which is used inside the ColorPicker.

The Popup implements this OnAfterRedrawAsync method:

protected override async Task OnAfterRenderAsync(bool firstRender)
{
	if (!firstRender)
	{
		if (shouldToggle)
		{
			await JSRuntime.InvokeVoidAsync("Radzen.togglePopup", target, GetId(), false, Reference, nameof(OnClose));
		}

		shouldToggle = false;
	}
}

Please notice, the flag shouldToggle = false; is set after the await JSRuntime.InvokeVoidAsync.

What is in some cases happening is that during that awaiting another rendering is triggered causing that another OnAfterRenderAsync is called before the first awaiting is completed. It causes the second await JSRuntime.InvokeVoidAsync is called.

This second call of JSRuntime.InvokeVoidAsync then closes the popup. (The effect is that the popup opens and after few milliseconds closes.)

Unfortunately I cannot provide a simple source code to reproduce the issue. It always happens in my code but I could not find a simple code which would trigger the second redraw during JSRuntime.InvokeVoidAsync.

The solution could be to move shouldToggle = false; before the await JSRuntime.InvokeVoidAsync. So that if a subsequent render happens the await JSRuntime.InvokeVoidAsync is not called.

Originally created by @OndrejUzovic on GitHub (May 29, 2023). It seems there is a kind of race-condition in the toggle functionality of Popup which is used inside the ColorPicker. The Popup implements this `OnAfterRedrawAsync` method: ``` protected override async Task OnAfterRenderAsync(bool firstRender) { if (!firstRender) { if (shouldToggle) { await JSRuntime.InvokeVoidAsync("Radzen.togglePopup", target, GetId(), false, Reference, nameof(OnClose)); } shouldToggle = false; } } ``` Please notice, the flag `shouldToggle = false;` is set after the `await JSRuntime.InvokeVoidAsync`. What is in some cases happening is that during that awaiting another rendering is triggered causing that another OnAfterRenderAsync is called before the first awaiting is completed. It causes the second `await JSRuntime.InvokeVoidAsync` is called. This second call of `JSRuntime.InvokeVoidAsync` then closes the popup. (The effect is that the popup opens and after few milliseconds closes.) Unfortunately I cannot provide a simple source code to reproduce the issue. It always happens in my code but I could not find a simple code which would trigger the second redraw during `JSRuntime.InvokeVoidAsync`. The solution could be to move `shouldToggle = false;` before the `await JSRuntime.InvokeVoidAsync`. So that if a subsequent render happens the `await JSRuntime.InvokeVoidAsync` is not called.
Author
Owner

@akorchev commented on GitHub (May 30, 2023):

Feel free to open a pull request.

@akorchev commented on GitHub (May 30, 2023): Feel free to open a pull request.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#858