WebWindow icon indicating copy to clipboard operation
WebWindow copied to clipboard

Two bound events shortly firing after eachother trigger concurrency bug.

Open jspuij opened this issue 4 years ago • 0 comments

Minimal Repro here:

https://github.com/jspuij/WebWindow/tree/eventbug

The keydown and oninput events fire shortly after eachother and trigger some sort of concurrency issue. The error message to the console is:

Uncaught (in promise) Error: System.ArgumentException: There is no event handler associated with this event. EventId: '7'. (Parameter 'eventHandlerId')
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.DispatchEventAsync(/UInt64 eventHandlerId, EventFieldInfo fieldInfo, EventArgs eventArgs)
   at WebWindows.Blazor.JSInteropMethods.DispatchEvent(/WebEventDescriptor eventDescriptor, String eventArgsJson)
    at Object.endInvokeDotNetFromJS (Microsoft.JSInterop.js:162)
    at Boot.Desktop.ts:33
    at IPC.ts:44
    at Array.forEach (<anonymous>)
    at IPC.ts:44
    at EventTarget.<anonymous> (<anonymous>:1:202)
    at <anonymous>:1:650
    at <anonymous>:1:676

What seems to happen is that the renderer does not like asynchronous dispatch of multiple events in such short order. I've written the IPC messages to the debugger, and the order seems to be:

ipc:BeginInvokeDotNetFromJS ["1","WebWindow","DispatchEvent",0,"[{\"browserRendererId\":0,\"eventHandlerId\":3,\"eventArgsType\":\"keyboard\",\"eventFieldInfo\":{\"componentId\":6,\"fieldValue\":\"\"}},\"{\\\"type\\\":\\\"keydown\\\",\\\"key\\\":\\\"Unidentified\\\",\\\"code\\\":\\\"\\\",\\\"location\\\":0,\\\"repeat\\\":false,\\\"ctrlKey\\\":false,\\\"shiftKey\\\":false,\\\"altKey\\\":false,\\\"metaKey\\\":false}\"]"]
ipc:BeginInvokeDotNetFromJS ["2","WebWindow","DispatchEvent",0,"[{\"browserRendererId\":0,\"eventHandlerId\":4,\"eventArgsType\":\"change\",\"eventFieldInfo\":{\"componentId\":6,\"fieldValue\":\"a\"}},\"{\\\"type\\\":\\\"input\\\",\\\"value\\\":\\\"a\\\"}\"]"]
JS.RenderBatch:[0,"BgAAAAEAAAADAAAAAQAAAAAAAAD/////AQAAAAAAAAABAAAAAwAAAAAAAAD/////BQAAAAAAAAAAAAAAAQAAAAQAAAAAAAAAB29uaW5wdXRIAAAAGAAAACAAAAA4AAAAPAAAAFAAAAA="]
JS.EndInvokeDotNet:["1",true]
JS.EndInvokeDotNet:["2",false,"System.ArgumentException: There is no event handler associated with this event. EventId: \u00274\u0027.

What I think happens is that either the render or first EndInvokeDotNet clears up all the remaining eventHandlerIds, and subsequently the second EndInvokeDotNet fails. This halts the updating of the binding. (keydown is processed as it's the first event).

I'm not familiar enough with the inner workings of the renderer and dispatcher to tackle this easily myself.

jspuij avatar Mar 16 '20 18:03 jspuij