Skip to content

Enable debounce / throttling for events #10522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mkArtakMSFT opened this issue May 24, 2019 · 11 comments
Open

Enable debounce / throttling for events #10522

mkArtakMSFT opened this issue May 24, 2019 · 11 comments
Labels
affected-medium This issue impacts approximately half of our customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-component-model Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc) Needs: Design This issue requires design work before implementating. Pillar: Technical Debt Priority:1 Work that is critical for the release, but we could probably ship without severity-major This label is used by an internal tool
Milestone

Comments

@mkArtakMSFT
Copy link
Contributor

This will allow the user to register for scroll events with some time period (100ms) which will filter out events happening within the period, and result in much fewer events being sent to the server.

@mkArtakMSFT mkArtakMSFT added enhancement This issue represents an ask for new feature or an enhancement to an existing one PRI: 1 - Required area-blazor Includes: Blazor, Razor Components labels May 24, 2019
@mkArtakMSFT mkArtakMSFT added this to the 3.0.0-preview8 milestone May 24, 2019
@arivoir
Copy link

arivoir commented May 24, 2019

Apart from having a delay, the events should be automatically dispatched, and filtered, depending on the real time the event is taking to be processed in the server(notice the network latency and the time involved in process the request counts).

Something like this

@functions
{
    object currentEventValue;
    System.Threading.SemaphoreSlim semaphore;

    private async void OnNativeEvent(string value)
    {
        try
        {
            currentEventValue = value;
            await Task.Delay(100);
            await semaphore.WaitAsync();
            if (currentEventValue == value)
            {
                await CallEventAsync();
            }
        }
        finally
        {
            semaphore.Release();
        }
    }
}

@Andrzej-W
Copy link

I asked for this about year ago. Unfortunately the issue was closed with suggestion that I can do it using some JavaScript code. If it will be implemented it should be possible to use throttling and debouncing in all events. Think about resize events, dragging, or input events when you want to implement incremental search and you don't want to query database after each keystroke.

@mkArtakMSFT mkArtakMSFT modified the milestones: 3.0.0-preview8, 3.1.0 Jun 24, 2019
@mkArtakMSFT mkArtakMSFT added the Needs: Design This issue requires design work before implementating. label Jun 24, 2019
@mkArtakMSFT mkArtakMSFT modified the milestones: 3.1.0, 5.0.0 Aug 12, 2019
@ctrl-alt-d
Copy link

Maybe you can use a Timer as workaround.

@ghost
Copy link

ghost commented Jun 29, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@ghost
Copy link

ghost commented Dec 19, 2023

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@ericgrantholland
Copy link

ericgrantholland commented Mar 21, 2024

I think this is a necessary feature to work with many of the events already exposed on Blazor side, especially for ServerSide Blazor. Really don't want OnMouseOver event firing a million times sending Signal R messages at that rate. I know there is a way around this with custom JS but it's a huge hassle. Need to write both JSSetup and JSCleanup for every event you want to handle.

Would be really cool if you could set the interval directly from razor syntax, similar to how stopPropagation and preventDefault work now. See below:

<div @onmouseover="@OnMouseOver" @onmouseover:throttle="160" >
This div mouse over event throttles 160ms
</div>

<div @onmouseover="@OnMouseOver" @onmouseover:debounce="500" >
This div mouse over event debounces 500ms
</div>

Without this level of control, many already exposed events aren't useful in blazor. Fire too often and cause problems.

@mkArtakMSFT mkArtakMSFT modified the milestones: .NET 10 Planning, Backlog Nov 1, 2024
@MrDach
Copy link

MrDach commented Feb 11, 2025

I think this is a necessary feature to work with many of the events already exposed on Blazor side, especially for ServerSide Blazor. Really don't want OnMouseOver event firing a million times sending Signal R messages at that rate. I know there is a way around this with custom JS but it's a huge hassle. Need to write both JSSetup and JSCleanup for every event you want to handle.

Would be really cool if you could set the interval directly from razor syntax, similar to how stopPropagation and preventDefault work now. See below:

<div @onmouseover="@OnMouseOver" @onmouseover:throttle="160" >
This div mouse over event throttles 160ms
</div>

<div @onmouseover="@OnMouseOver" @onmouseover:debounce="500" >
This div mouse over event debounces 500ms
</div>

Without this level of control, many already exposed events aren't useful in blazor. Fire too often and cause problems.

Agreed that having to do some custom setup to handle this is a hassle.
Something like the suggested solution would be fantastic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected-medium This issue impacts approximately half of our customers area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-component-model Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc) Needs: Design This issue requires design work before implementating. Pillar: Technical Debt Priority:1 Work that is critical for the release, but we could probably ship without severity-major This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests