From 050fa47d0f7611cd29c6ff54d9ced828f2d0e825 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 19 Jul 2021 15:26:05 -0700 Subject: [PATCH 1/2] Make sync and async disposal of Renderer behave the same --- .../Components/src/RenderTree/Renderer.cs | 67 +++++++------------ .../Web.JS/dist/Release/blazor.webview.js | 2 +- 2 files changed, 25 insertions(+), 44 deletions(-) diff --git a/src/Components/Components/src/RenderTree/Renderer.cs b/src/Components/Components/src/RenderTree/Renderer.cs index c71d54062d28..8351d84e1de0 100644 --- a/src/Components/Components/src/RenderTree/Renderer.cs +++ b/src/Components/Components/src/RenderTree/Renderer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. #nullable disable warnings @@ -42,7 +42,6 @@ public abstract partial class Renderer : IDisposable, IAsyncDisposable private bool _isBatchInProgress; private ulong _lastEventHandlerId; private List? _pendingTasks; - private Task? _disposeTask; /// /// Allows the caller to handle exceptions from the SynchronizationContext when one is available. @@ -956,10 +955,31 @@ private void HandleExceptionViaErrorBoundary(Exception error, ComponentState? er /// Releases all resources currently used by this instance. /// /// if this method is being invoked by , otherwise . - protected virtual void Dispose(bool disposing) + protected virtual void Dispose(bool disposing) => DisposeAsync().AsTask().GetAwaiter().GetResult(); + + /// + /// Releases all resources currently used by this instance. + /// + public void Dispose() + { + Dispose(disposing: true); + } + + /// + public async ValueTask DisposeAsync() { + if (Disposed) + { + return; + } + Disposed = true; + if (TestableMetadataUpdate.IsSupported) + { + HotReloadManager.OnDeltaApplied -= RenderRootComponentsOnHotReload; + } + // It's important that we handle all exceptions here before reporting any of them. // This way we can dispose all components before an error handler kicks in. List exceptions = null; @@ -1012,7 +1032,7 @@ protected virtual void Dispose(bool disposing) if (asyncDisposables?.Count >= 1) { - _disposeTask = HandleAsyncExceptions(asyncDisposables); + await HandleAsyncExceptions(asyncDisposables); } async Task HandleAsyncExceptions(List tasks) @@ -1046,44 +1066,5 @@ void NotifyExceptions(List exceptions) } } } - - /// - /// Releases all resources currently used by this instance. - /// - public void Dispose() - { - Dispose(disposing: true); - } - - /// - public async ValueTask DisposeAsync() - { - if (TestableMetadataUpdate.IsSupported) - { - HotReloadManager.OnDeltaApplied -= RenderRootComponentsOnHotReload; - } - - if (Disposed) - { - return; - } - - if (_disposeTask != null) - { - await _disposeTask; - } - else - { - Dispose(); - if (_disposeTask != null) - { - await _disposeTask; - } - else - { - await default(ValueTask); - } - } - } } } diff --git a/src/Components/Web.JS/dist/Release/blazor.webview.js b/src/Components/Web.JS/dist/Release/blazor.webview.js index 2ce9e9dd26d7..085dfb0656f5 100644 --- a/src/Components/Web.JS/dist/Release/blazor.webview.js +++ b/src/Components/Web.JS/dist/Release/blazor.webview.js @@ -1 +1 @@ -(()=>{"use strict";var e,t,n;!function(e){window.DotNet=e;const t=[],n=new Map;class r{constructor(e){this._jsObject=e,this._cachedFunctions=new Map}findFunction(e){const t=this._cachedFunctions.get(e);if(t)return t;let n,r=this._jsObject;if(e.split(".").forEach((t=>{if(!(t in r))throw new Error(`Could not find '${e}' ('${t}' was undefined).`);n=r,r=r[t]})),r instanceof Function)return r=r.bind(n),this._cachedFunctions.set(e,r),r;throw new Error(`The value '${e}' is not a function.`)}getWrappedObject(){return this._jsObject}}const o="__jsObjectId",a={},i={0:new r(window)};i[0]._cachedFunctions.set("import",(e=>("string"==typeof e&&e.startsWith("./")&&(e=document.baseURI+e.substr(2)),import(e))));let s,c=1,l=1,u=null;function d(e){t.push(e)}function f(e){if(e&&"object"==typeof e){i[l]=new r(e);const t={[o]:l};return l++,t}throw new Error(`Cannot create a JSObjectReference from the value '${e}'.`)}function h(e){let t=-1;if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),e instanceof Blob)t=e.size;else{if(!(e.buffer instanceof ArrayBuffer))throw new Error("Supplied value is not a typed array or blob.");if(void 0===e.byteLength)throw new Error(`Cannot create a JSStreamReference from the value '${e}' as it doesn't have a byteLength.`);t=e.byteLength}const n={__jsStreamReferenceLength:t};try{const t=f(e);n.__jsObjectId=t.__jsObjectId}catch{throw new Error(`Cannot create a JSStreamReference from the value '${e}'.`)}return n}function m(e){return e?JSON.parse(e,((e,n)=>t.reduce(((t,n)=>n(e,t)),n))):null}function p(e,t,n,r){const o=g();if(o.invokeDotNetFromJS){const a=A(r),i=o.invokeDotNetFromJS(e,t,n,a);return i?m(i):null}throw new Error("The current dispatcher does not support synchronous calls from JS to .NET. Use invokeMethodAsync instead.")}function v(e,t,n,r){if(e&&n)throw new Error(`For instance method calls, assemblyName should be null. Received '${e}'.`);const o=c++,i=new Promise(((e,t)=>{a[o]={resolve:e,reject:t}}));try{const a=A(r);g().beginInvokeDotNetFromJS(o,e,t,n,a)}catch(e){b(o,!1,e)}return i}function g(){if(null!==u)return u;throw new Error("No .NET call dispatcher has been set.")}function b(e,t,n){if(!a.hasOwnProperty(e))throw new Error(`There is no pending async call with ID ${e}.`);const r=a[e];delete a[e],t?r.resolve(n):r.reject(n)}function y(e){return e instanceof Error?`${e.message}\n${e.stack}`:e?e.toString():"null"}function E(e,t){let n=i[t];if(n)return n.findFunction(e);throw new Error(`JS object instance with ID ${t} does not exist (has it been disposed?).`)}function w(e){delete i[e]}e.attachDispatcher=function(e){u=e},e.attachReviver=d,e.invokeMethod=function(e,t,...n){return p(e,t,null,n)},e.invokeMethodAsync=function(e,t,...n){return v(e,t,null,n)},e.createJSObjectReference=f,e.createJSStreamReference=h,e.disposeJSObjectReference=function(e){const t=e&&e.__jsObjectId;"number"==typeof t&&w(t)},function(e){e[e.Default=0]="Default",e[e.JSObjectReference=1]="JSObjectReference",e[e.JSStreamReference=2]="JSStreamReference"}(s=e.JSCallResultType||(e.JSCallResultType={})),e.jsCallDispatcher={findJSFunction:E,disposeJSObjectReferenceById:w,invokeJSFromDotNet:(e,t,n,r)=>{const o=D(E(e,r).apply(null,m(t)),n);return null==o?null:A(o)},beginInvokeJSFromDotNet:(e,t,n,r,o)=>{const a=new Promise((e=>{e(E(t,o).apply(null,m(n)))}));e&&a.then((t=>g().endInvokeJSFromDotNet(e,!0,A([e,!0,D(t,r)]))),(t=>g().endInvokeJSFromDotNet(e,!1,JSON.stringify([e,!1,y(t)]))))},endInvokeDotNetFromJS:(e,t,n)=>{const r=t?m(n):new Error(n);b(parseInt(e),t,r)},receiveByteArray:(e,t)=>{n.set(e,t)}};class I{constructor(e){this._id=e}invokeMethod(e,...t){return p(null,e,this._id,t)}invokeMethodAsync(e,...t){return v(null,e,this._id,t)}dispose(){v(null,"__Dispose",this._id,null).catch((e=>console.error(e)))}serializeAsArg(){return{__dotNetObject:this._id}}}const S="__byte[]";function D(e,t){switch(t){case s.Default:return e;case s.JSObjectReference:return f(e);case s.JSStreamReference:return h(e);default:throw new Error(`Invalid JS call result type '${t}'.`)}}d((function(e,t){if(t&&"object"==typeof t){if(t.hasOwnProperty("__dotNetObject"))return new I(t.__dotNetObject);if(t.hasOwnProperty(o)){const e=t.__jsObjectId,n=i[e];if(n)return n.getWrappedObject();throw new Error(`JS object instance with Id '${e}' does not exist. It may have been disposed.`)}if(t.hasOwnProperty(S)){const e=t["__byte[]"],r=n.get(e);if(void 0===r)throw new Error(`Byte array index '${e}' does not exist.`);return r}}return t}));let C=0;function A(e){return C=0,JSON.stringify(e,T)}function T(e,t){if(t instanceof I)return t.serializeAsArg();if(t instanceof Uint8Array){u.sendByteArray(C,t);const e={[S]:C};return C++,e}return t}}(e||(e={})),function(e){e[e.prependFrame=1]="prependFrame",e[e.removeFrame=2]="removeFrame",e[e.setAttribute=3]="setAttribute",e[e.removeAttribute=4]="removeAttribute",e[e.updateText=5]="updateText",e[e.stepIn=6]="stepIn",e[e.stepOut=7]="stepOut",e[e.updateMarkup=8]="updateMarkup",e[e.permutationListEntry=9]="permutationListEntry",e[e.permutationListEnd=10]="permutationListEnd"}(t||(t={})),function(e){e[e.element=1]="element",e[e.text=2]="text",e[e.attribute=3]="attribute",e[e.component=4]="component",e[e.region=5]="region",e[e.elementReferenceCapture=6]="elementReferenceCapture",e[e.markup=8]="markup"}(n||(n={}));class r{constructor(e,t){this.componentId=e,this.fieldValue=t}static fromEvent(e,t){const n=t.target;if(n instanceof Element){const t=function(e){return e instanceof HTMLInputElement?e.type&&"checkbox"===e.type.toLowerCase()?{value:e.checked}:{value:e.value}:e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement?{value:e.value}:null}(n);if(t)return new r(e,t.value)}return null}}let o;function a(e,t){if(!o)throw new Error("eventDispatcher not initialized. Call 'setEventDispatcher' to configure it.");o(e,t)}const i=new Map,s=new Map,c={createEventArgs:()=>({})},l=[];function u(e){return i.get(e)}function d(e){const t=i.get(e);return(null==t?void 0:t.browserEventName)||e}function f(e,t){e.forEach((e=>i.set(e,t)))}function h(e){const t=[];for(let n=0;ne.selected)).map((e=>e.value))}}return{value:function(e){return!!e&&"INPUT"===e.tagName&&"checkbox"===e.getAttribute("type")}(t)?!!t.checked:t.value}}}),f(["copy","cut","paste"],c),f(["drag","dragend","dragenter","dragleave","dragover","dragstart","drop"],{createEventArgs:e=>{return{...m(t=e),dataTransfer:t.dataTransfer?{dropEffect:t.dataTransfer.dropEffect,effectAllowed:t.dataTransfer.effectAllowed,files:Array.from(t.dataTransfer.files).map((e=>e.name)),items:Array.from(t.dataTransfer.items).map((e=>({kind:e.kind,type:e.type}))),types:t.dataTransfer.types}:null};var t}}),f(["focus","blur","focusin","focusout"],c),f(["keydown","keyup","keypress"],{createEventArgs:e=>{return{key:(t=e).key,code:t.code,location:t.location,repeat:t.repeat,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey};var t}}),f(["contextmenu","click","mouseover","mouseout","mousemove","mousedown","mouseup","dblclick"],{createEventArgs:e=>m(e)}),f(["error"],{createEventArgs:e=>{return{message:(t=e).message,filename:t.filename,lineno:t.lineno,colno:t.colno};var t}}),f(["loadstart","timeout","abort","load","loadend","progress"],{createEventArgs:e=>{return{lengthComputable:(t=e).lengthComputable,loaded:t.loaded,total:t.total};var t}}),f(["touchcancel","touchend","touchmove","touchenter","touchleave","touchstart"],{createEventArgs:e=>{return{detail:(t=e).detail,touches:h(t.touches),targetTouches:h(t.targetTouches),changedTouches:h(t.changedTouches),ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,type:t.type};var t}}),f(["gotpointercapture","lostpointercapture","pointercancel","pointerdown","pointerenter","pointerleave","pointermove","pointerout","pointerover","pointerup"],{createEventArgs:e=>{return{...m(t=e),pointerId:t.pointerId,width:t.width,height:t.height,pressure:t.pressure,tiltX:t.tiltX,tiltY:t.tiltY,pointerType:t.pointerType,isPrimary:t.isPrimary};var t}}),f(["wheel","mousewheel"],{createEventArgs:e=>{return{...m(t=e),deltaX:t.deltaX,deltaY:t.deltaY,deltaZ:t.deltaZ,deltaMode:t.deltaMode};var t}}),f(["toggle"],c);const p=["date","datetime-local","month","time","week"],v=I(["abort","blur","change","error","focus","load","loadend","loadstart","mouseenter","mouseleave","progress","reset","scroll","submit","unload","toggle","DOMNodeInsertedIntoDocument","DOMNodeRemovedFromDocument"]),g={submit:!0},b=I(["click","dblclick","mousedown","mousemove","mouseup"]);class y{constructor(e){this.browserRendererId=e,this.afterClickCallbacks=[];const t=++y.nextEventDelegatorId;this.eventsCollectionKey=`_blazorEvents_${t}`,this.eventInfoStore=new E(this.onGlobalEvent.bind(this))}setListener(e,t,n,r){const o=this.getEventHandlerInfosForElement(e,!0),a=o.getHandler(t);if(a)this.eventInfoStore.update(a.eventHandlerId,n);else{const a={element:e,eventName:t,eventHandlerId:n,renderingComponentId:r};this.eventInfoStore.add(a),o.setHandler(t,a)}}getHandler(e){return this.eventInfoStore.get(e)}removeListener(e){const t=this.eventInfoStore.remove(e);if(t){const e=t.element,n=this.getEventHandlerInfosForElement(e,!1);n&&n.removeHandler(t.eventName)}}notifyAfterClick(e){this.afterClickCallbacks.push(e),this.eventInfoStore.addGlobalListener("click")}setStopPropagation(e,t,n){this.getEventHandlerInfosForElement(e,!0).stopPropagation(t,n)}setPreventDefault(e,t,n){this.getEventHandlerInfosForElement(e,!0).preventDefault(t,n)}onGlobalEvent(e){if(!(e.target instanceof Element))return;this.dispatchGlobalEventToAllElements(e.type,e);const t=(n=e.type,s.get(n));var n;t&&t.forEach((t=>this.dispatchGlobalEventToAllElements(t,e))),"click"===e.type&&this.afterClickCallbacks.forEach((t=>t(e)))}dispatchGlobalEventToAllElements(e,t){let n=t.target,o=null,i=!1;const s=v.hasOwnProperty(e);let c=!1;for(;n;){const f=this.getEventHandlerInfosForElement(n,!1);if(f){const s=f.getHandler(e);if(s&&(l=n,d=t.type,!((l instanceof HTMLButtonElement||l instanceof HTMLInputElement||l instanceof HTMLTextAreaElement||l instanceof HTMLSelectElement)&&b.hasOwnProperty(d)&&l.disabled))){if(!i){const n=u(e);o=(null==n?void 0:n.createEventArgs)?n.createEventArgs(t):{},i=!0}g.hasOwnProperty(t.type)&&t.preventDefault(),a({browserRendererId:this.browserRendererId,eventHandlerId:s.eventHandlerId,eventName:e,eventFieldInfo:r.fromEvent(s.renderingComponentId,t)},o)}f.stopPropagation(e)&&(c=!0),f.preventDefault(e)&&t.preventDefault()}n=s||c?null:n.parentElement}var l,d}getEventHandlerInfosForElement(e,t){return e.hasOwnProperty(this.eventsCollectionKey)?e[this.eventsCollectionKey]:t?e[this.eventsCollectionKey]=new w:null}}y.nextEventDelegatorId=0;class E{constructor(e){this.globalListener=e,this.infosByEventHandlerId={},this.countByEventName={},l.push(this.handleEventNameAliasAdded.bind(this))}add(e){if(this.infosByEventHandlerId[e.eventHandlerId])throw new Error(`Event ${e.eventHandlerId} is already tracked`);this.infosByEventHandlerId[e.eventHandlerId]=e,this.addGlobalListener(e.eventName)}get(e){return this.infosByEventHandlerId[e]}addGlobalListener(e){if(e=d(e),this.countByEventName.hasOwnProperty(e))this.countByEventName[e]++;else{this.countByEventName[e]=1;const t=v.hasOwnProperty(e);document.addEventListener(e,this.globalListener,t)}}update(e,t){if(this.infosByEventHandlerId.hasOwnProperty(t))throw new Error(`Event ${t} is already tracked`);const n=this.infosByEventHandlerId[e];delete this.infosByEventHandlerId[e],n.eventHandlerId=t,this.infosByEventHandlerId[t]=n}remove(e){const t=this.infosByEventHandlerId[e];if(t){delete this.infosByEventHandlerId[e];const n=d(t.eventName);0==--this.countByEventName[n]&&(delete this.countByEventName[n],document.removeEventListener(n,this.globalListener))}return t}handleEventNameAliasAdded(e,t){if(this.countByEventName.hasOwnProperty(e)){const n=this.countByEventName[e];delete this.countByEventName[e],document.removeEventListener(e,this.globalListener),this.addGlobalListener(t),this.countByEventName[t]+=n-1}}}class w{constructor(){this.handlers={},this.preventDefaultFlags=null,this.stopPropagationFlags=null}getHandler(e){return this.handlers.hasOwnProperty(e)?this.handlers[e]:null}setHandler(e,t){this.handlers[e]=t}removeHandler(e){delete this.handlers[e]}preventDefault(e,t){return void 0!==t&&(this.preventDefaultFlags=this.preventDefaultFlags||{},this.preventDefaultFlags[e]=t),!!this.preventDefaultFlags&&this.preventDefaultFlags[e]}stopPropagation(e,t){return void 0!==t&&(this.stopPropagationFlags=this.stopPropagationFlags||{},this.stopPropagationFlags[e]=t),!!this.stopPropagationFlags&&this.stopPropagationFlags[e]}}function I(e){const t={};return e.forEach((e=>{t[e]=!0})),t}const S=P("_blazorLogicalChildren"),D=P("_blazorLogicalParent"),C=P("_blazorLogicalEnd");function A(e,t){if(e.childNodes.length>0&&!t)throw new Error("New logical elements must start empty, or allowExistingContents must be true");return S in e||(e[S]=[]),e}function T(e,t){const n=document.createComment("!");return N(n,e,t),n}function N(e,t,n){const r=e;if(e instanceof Comment&&O(r)&&O(r).length>0)throw new Error("Not implemented: inserting non-empty logical container");if(R(r))throw new Error("Not implemented: moving existing logical children");const o=O(t);if(n0;)k(n,0)}const r=n;r.parentNode.removeChild(r)}function R(e){return e[D]||null}function F(e,t){return O(e)[t]}function _(e){var t=L(e);return"http://www.w3.org/2000/svg"===t.namespaceURI&&"foreignObject"!==t.tagName}function O(e){return e[S]}function x(e,t){const n=O(e);t.forEach((e=>{e.moveRangeStart=n[e.fromSiblingIndex],e.moveRangeEnd=M(e.moveRangeStart)})),t.forEach((t=>{const r=t.moveToBeforeMarker=document.createComment("marker"),o=n[t.toSiblingIndex+1];o?o.parentNode.insertBefore(r,o):H(r,e)})),t.forEach((e=>{const t=e.moveToBeforeMarker,n=t.parentNode,r=e.moveRangeStart,o=e.moveRangeEnd;let a=r;for(;a;){const e=a.nextSibling;if(n.insertBefore(a,t),a===o)break;a=e}n.removeChild(t)})),t.forEach((e=>{n[e.toSiblingIndex]=e.moveRangeStart}))}function L(e){if(e instanceof Element)return e;if(e instanceof Comment)return e.parentNode;throw new Error("Not a valid logical element")}function B(e){const t=O(R(e));return t[Array.prototype.indexOf.call(t,e)+1]||null}function H(e,t){if(t instanceof Element)t.appendChild(e);else{if(!(t instanceof Comment))throw new Error(`Cannot append node because the parent is not a valid logical element. Parent: ${t}`);{const n=B(t);n?n.parentNode.insertBefore(e,n):H(e,R(t))}}}function M(e){if(e instanceof Element)return e;const t=B(e);if(t)return t.previousSibling;{const t=R(e);return t instanceof Element?t.lastChild:M(t)}}function P(e){return"function"==typeof Symbol?Symbol():e}function U(e){return`_bl_${e}`}e.attachReviver(((e,t)=>t&&"object"==typeof t&&t.hasOwnProperty("__internalId")&&"string"==typeof t.__internalId?function(e){const t=`[${U(e)}]`;return document.querySelector(t)}(t.__internalId):t));const j="_blazorDeferredValue",J=document.createElement("template"),$=document.createElementNS("http://www.w3.org/2000/svg","g"),z={},K="__internal_",V="preventDefault_",X="stopPropagation_";class Y{constructor(e){this.childComponentLocations={},this.eventDelegator=new y(e),this.eventDelegator.notifyAfterClick((e=>{if(!ne)return;if(0!==e.button||function(e){return e.ctrlKey||e.shiftKey||e.altKey||e.metaKey}(e))return;if(e.defaultPrevented)return;const t=function(e){const t=!window._blazorDisableComposedPath&&e.composedPath&&e.composedPath();if(t){for(let e=0;ece(!1))))},enableNavigationInterception:function(){ne=!0},navigateTo:ie,getBaseURI:()=>document.baseURI,getLocationHref:()=>location.href};function ie(e,t,n=!1){const r=ue(e),o=t instanceof Object?t:{forceLoad:t,replaceHistoryEntry:n};!o.forceLoad&&fe(r)?se(r,!1,o.replaceHistoryEntry):function(e,t){if(location.href===e){const t=e+"?";history.replaceState(null,"",t),location.replace(e)}else t?location.replace(e):location.href=e}(e,o.replaceHistoryEntry)}function se(e,t,n){te=!0,n?history.replaceState(null,"",e):history.pushState(null,"",e),ce(t)}async function ce(e){oe&&await oe(location.href,e)}let le;function ue(e){return le=le||document.createElement("a"),le.href=e,le.href}function de(e,t){return e?e.tagName===t?e:de(e.parentElement,t):null}function fe(e){const t=(n=document.baseURI).substr(0,n.lastIndexOf("/")+1);var n;return e.startsWith(t)}const he={init:function(e,t,n,r=50){const o=pe(t);(o||document.documentElement).style.overflowAnchor="none";const a=new IntersectionObserver((function(r){r.forEach((r=>{var o;if(!r.isIntersecting)return;const a=t.getBoundingClientRect(),i=n.getBoundingClientRect().top-a.bottom,s=null===(o=r.rootBounds)||void 0===o?void 0:o.height;r.target===t?e.invokeMethodAsync("OnSpacerBeforeVisible",r.intersectionRect.top-r.boundingClientRect.top,i,s):r.target===n&&n.offsetHeight>0&&e.invokeMethodAsync("OnSpacerAfterVisible",r.boundingClientRect.bottom-r.intersectionRect.bottom,i,s)}))}),{root:o,rootMargin:`${r}px`});a.observe(t),a.observe(n);const i=c(t),s=c(n);function c(e){const t=new MutationObserver((()=>{a.unobserve(e),a.observe(e)}));return t.observe(e,{attributes:!0}),t}me[e._id]={intersectionObserver:a,mutationObserverBefore:i,mutationObserverAfter:s}},dispose:function(e){const t=me[e._id];t&&(t.intersectionObserver.disconnect(),t.mutationObserverBefore.disconnect(),t.mutationObserverAfter.disconnect(),e.dispose(),delete me[e._id])}},me={};function pe(e){return e?"visible"!==getComputedStyle(e).overflowY?e:pe(e.parentElement):null}function ve(e,t){const n=e._blazorFilesById[t];if(!n)throw new Error(`There is no file with ID ${t}. The file list may have changed.`);return n}const ge={navigateTo:ie,registerCustomEventType:function(e,t){if(!t)throw new Error("The options parameter is required.");if(i.has(e))throw new Error(`The event '${e}' is already registered.`);if(t.browserEventName){const n=s.get(t.browserEventName);n?n.push(e):s.set(t.browserEventName,[e]),l.forEach((n=>n(e,t.browserEventName)))}i.set(e,t)},_internal:{navigationManager:ae,domWrapper:{focus:function(e,t){if(!(e instanceof HTMLElement))throw new Error("Unable to focus an invalid element.");e.focus({preventScroll:t})},focusBySelector:function(e){const t=document.querySelector(e);t&&(t.hasAttribute("tabindex")||(t.tabIndex=-1),t.focus())}},Virtualize:he,PageTitle:{getAndRemoveExistingTitle:function(){var e;const t=document.getElementsByTagName("title");if(0===t.length)return null;let n=null;for(let r=t.length-1;r>=0;r--){const o=t[r],a=o.previousSibling;a instanceof Comment&&null!==R(a)||(null===n&&(n=o.textContent),null===(e=o.parentNode)||void 0===e||e.removeChild(o))}return n}},InputFile:{init:function(e,t){t._blazorInputFileNextFileId=0,t.addEventListener("click",(function(){t.value=""})),t.addEventListener("change",(function(){t._blazorFilesById={};const n=Array.prototype.map.call(t.files,(function(e){const n={id:++t._blazorInputFileNextFileId,lastModified:new Date(e.lastModified).toISOString(),name:e.name,size:e.size,contentType:e.type,readPromise:void 0,arrayBuffer:void 0,blob:e};return t._blazorFilesById[n.id]=n,n}));e.invokeMethodAsync("NotifyChange",n)}))},toImageFile:async function(e,t,n,r,o){const a=ve(e,t),i=await new Promise((function(e){const t=new Image;t.onload=function(){e(t)},t.src=URL.createObjectURL(a.blob)})),s=await new Promise((function(e){var t;const a=Math.min(1,r/i.width),s=Math.min(1,o/i.height),c=Math.min(a,s),l=document.createElement("canvas");l.width=Math.round(i.width*c),l.height=Math.round(i.height*c),null===(t=l.getContext("2d"))||void 0===t||t.drawImage(i,0,0,l.width,l.height),l.toBlob(e,n)})),c={id:++e._blazorInputFileNextFileId,lastModified:a.lastModified,name:a.name,size:(null==s?void 0:s.size)||0,contentType:n,blob:s||a.blob};return e._blazorFilesById[c.id]=c,c},readFileData:async function(e,t){return ve(e,t).blob}},getJSDataStreamChunk:async function(e,t,n){return e instanceof Blob?await async function(e,t,n){const r=e.slice(t,t+n),o=await r.arrayBuffer();return new Uint8Array(o)}(e,t,n):function(e,t,n){return new Uint8Array(e.buffer,e.byteOffset+t,n)}(e,t,n)}}};window.Blazor=ge;let be=!1;const ye="function"==typeof TextDecoder?new TextDecoder("utf-8"):null,Ee=ye?ye.decode.bind(ye):function(e){let t=0;const n=e.length,r=[],o=[];for(;t65535&&(o-=65536,r.push(o>>>10&1023|55296),o=56320|1023&o),r.push(o)}r.length>1024&&(o.push(String.fromCharCode.apply(null,r)),r.length=0)}return o.push(String.fromCharCode.apply(null,r)),o.join("")},we=Math.pow(2,32),Ie=Math.pow(2,21)-1;function Se(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24}function De(e,t){return e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24>>>0)}function Ce(e,t){const n=De(e,t+4);if(n>Ie)throw new Error(`Cannot read uint64 with high order part ${n}, because the result would exceed Number.MAX_SAFE_INTEGER.`);return n*we+De(e,t)}class Ae{constructor(e){this.batchData=e;const t=new Re(e);this.arrayRangeReader=new Fe(e),this.arrayBuilderSegmentReader=new _e(e),this.diffReader=new Te(e),this.editReader=new Ne(e,t),this.frameReader=new ke(e,t)}updatedComponents(){return Se(this.batchData,this.batchData.length-20)}referenceFrames(){return Se(this.batchData,this.batchData.length-16)}disposedComponentIds(){return Se(this.batchData,this.batchData.length-12)}disposedEventHandlerIds(){return Se(this.batchData,this.batchData.length-8)}updatedComponentsEntry(e,t){const n=e+4*t;return Se(this.batchData,n)}referenceFramesEntry(e,t){return e+20*t}disposedComponentIdsEntry(e,t){const n=e+4*t;return Se(this.batchData,n)}disposedEventHandlerIdsEntry(e,t){const n=e+8*t;return Ce(this.batchData,n)}}class Te{constructor(e){this.batchDataUint8=e}componentId(e){return Se(this.batchDataUint8,e)}edits(e){return e+4}editsEntry(e,t){return e+16*t}}class Ne{constructor(e,t){this.batchDataUint8=e,this.stringReader=t}editType(e){return Se(this.batchDataUint8,e)}siblingIndex(e){return Se(this.batchDataUint8,e+4)}newTreeIndex(e){return Se(this.batchDataUint8,e+8)}moveToSiblingIndex(e){return Se(this.batchDataUint8,e+8)}removedAttributeName(e){const t=Se(this.batchDataUint8,e+12);return this.stringReader.readString(t)}}class ke{constructor(e,t){this.batchDataUint8=e,this.stringReader=t}frameType(e){return Se(this.batchDataUint8,e)}subtreeLength(e){return Se(this.batchDataUint8,e+4)}elementReferenceCaptureId(e){const t=Se(this.batchDataUint8,e+4);return this.stringReader.readString(t)}componentId(e){return Se(this.batchDataUint8,e+8)}elementName(e){const t=Se(this.batchDataUint8,e+8);return this.stringReader.readString(t)}textContent(e){const t=Se(this.batchDataUint8,e+4);return this.stringReader.readString(t)}markupContent(e){const t=Se(this.batchDataUint8,e+4);return this.stringReader.readString(t)}attributeName(e){const t=Se(this.batchDataUint8,e+4);return this.stringReader.readString(t)}attributeValue(e){const t=Se(this.batchDataUint8,e+8);return this.stringReader.readString(t)}attributeEventHandlerId(e){return Ce(this.batchDataUint8,e+12)}}class Re{constructor(e){this.batchDataUint8=e,this.stringTableStartIndex=Se(e,e.length-4)}readString(e){if(-1===e)return null;{const n=Se(this.batchDataUint8,this.stringTableStartIndex+4*e),r=function(e,t){let n=0,r=0;for(let o=0;o<4;o++){const a=e[t+o];if(n|=(127&a)<{!function(e,t,n){const r="::after";let o=!1;e.endsWith(r)&&(e=e.slice(0,-r.length),o=!0);const a=document.querySelector(e);if(!a)throw new Error(`Could not find any element matching selector '${e}'.`);!function(e,t,n,r){let o=ee[0];o||(o=ee[0]=new Y(0)),o.attachRootComponentToLogicalElement(n,t,r)}(0,A(a,!0),t,o)}(t,e)},RenderBatch:(e,t)=>{try{const n=Je(t);(function(e,t){const n=ee[0];if(!n)throw new Error("There is no browser renderer with ID 0.");const r=t.arrayRangeReader,o=t.updatedComponents(),a=r.values(o),i=r.count(o),s=t.referenceFrames(),c=r.values(s),l=t.diffReader;for(let e=0;e{xe=!0,console.error(`${e}\n${t}`),async function(){let e=document.querySelector("#blazor-error-ui");e&&(e.style.display="block"),be||(be=!0,document.querySelectorAll("#blazor-error-ui .reload").forEach((e=>{e.onclick=function(e){location.reload(),e.preventDefault()}})),document.querySelectorAll("#blazor-error-ui .dismiss").forEach((e=>{e.onclick=function(e){const t=document.querySelector("#blazor-error-ui");t&&(t.style.display="none"),e.preventDefault()}})))}()},BeginInvokeJS:e.jsCallDispatcher.beginInvokeJSFromDotNet,EndInvokeDotNet:e.jsCallDispatcher.endInvokeDotNetFromJS,SendByteArrayToJS:je,Navigate:ae.navigateTo};window.external.receiveMessage((e=>{const n=function(e){if(xe||!e||!e.startsWith(Oe))return null;const t=e.substring(Oe.length),[n,...r]=JSON.parse(t);return{messageType:n,args:r}}(e);if(n){if(!t.hasOwnProperty(n.messageType))throw new Error(`Unsupported IPC message type '${n.messageType}'`);t[n.messageType].apply(null,n.args)}}))}(),e.attachDispatcher({beginInvokeDotNetFromJS:Be,endInvokeJSFromDotNet:He,sendByteArray:Me}),ae.enableNavigationInterception(),ae.listenForNavigationEvents(Pe),Ue("AttachPage",ae.getBaseURI(),ae.getLocationHref())}o=function(e,t){Ue("DispatchBrowserEvent",e,t)},ge.start=ze,document&&document.currentScript&&"false"!==document.currentScript.getAttribute("autostart")&&ze()})(); \ No newline at end of file +(()=>{"use strict";var e,t,n;!function(e){window.DotNet=e;const t=[],n=new Map;class r{constructor(e){this._jsObject=e,this._cachedFunctions=new Map}findFunction(e){const t=this._cachedFunctions.get(e);if(t)return t;let n,r=this._jsObject;if(e.split(".").forEach((t=>{if(!(t in r))throw new Error(`Could not find '${e}' ('${t}' was undefined).`);n=r,r=r[t]})),r instanceof Function)return r=r.bind(n),this._cachedFunctions.set(e,r),r;throw new Error(`The value '${e}' is not a function.`)}getWrappedObject(){return this._jsObject}}const o="__jsObjectId",a={},i={0:new r(window)};i[0]._cachedFunctions.set("import",(e=>("string"==typeof e&&e.startsWith("./")&&(e=document.baseURI+e.substr(2)),import(e))));let s,c=1,l=1,u=null;function d(e){t.push(e)}function f(e){if(e&&"object"==typeof e){i[l]=new r(e);const t={[o]:l};return l++,t}throw new Error(`Cannot create a JSObjectReference from the value '${e}'.`)}function h(e){let t=-1;if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),e instanceof Blob)t=e.size;else{if(!(e.buffer instanceof ArrayBuffer))throw new Error("Supplied value is not a typed array or blob.");if(void 0===e.byteLength)throw new Error(`Cannot create a JSStreamReference from the value '${e}' as it doesn't have a byteLength.`);t=e.byteLength}const n={__jsStreamReferenceLength:t};try{const t=f(e);n.__jsObjectId=t.__jsObjectId}catch{throw new Error(`Cannot create a JSStreamReference from the value '${e}'.`)}return n}function m(e){return e?JSON.parse(e,((e,n)=>t.reduce(((t,n)=>n(e,t)),n))):null}function p(e,t,n,r){const o=g();if(o.invokeDotNetFromJS){const a=A(r),i=o.invokeDotNetFromJS(e,t,n,a);return i?m(i):null}throw new Error("The current dispatcher does not support synchronous calls from JS to .NET. Use invokeMethodAsync instead.")}function v(e,t,n,r){if(e&&n)throw new Error(`For instance method calls, assemblyName should be null. Received '${e}'.`);const o=c++,i=new Promise(((e,t)=>{a[o]={resolve:e,reject:t}}));try{const a=A(r);g().beginInvokeDotNetFromJS(o,e,t,n,a)}catch(e){b(o,!1,e)}return i}function g(){if(null!==u)return u;throw new Error("No .NET call dispatcher has been set.")}function b(e,t,n){if(!a.hasOwnProperty(e))throw new Error(`There is no pending async call with ID ${e}.`);const r=a[e];delete a[e],t?r.resolve(n):r.reject(n)}function y(e){return e instanceof Error?`${e.message}\n${e.stack}`:e?e.toString():"null"}function E(e,t){let n=i[t];if(n)return n.findFunction(e);throw new Error(`JS object instance with ID ${t} does not exist (has it been disposed?).`)}function w(e){delete i[e]}e.attachDispatcher=function(e){u=e},e.attachReviver=d,e.invokeMethod=function(e,t,...n){return p(e,t,null,n)},e.invokeMethodAsync=function(e,t,...n){return v(e,t,null,n)},e.createJSObjectReference=f,e.createJSStreamReference=h,e.disposeJSObjectReference=function(e){const t=e&&e.__jsObjectId;"number"==typeof t&&w(t)},function(e){e[e.Default=0]="Default",e[e.JSObjectReference=1]="JSObjectReference",e[e.JSStreamReference=2]="JSStreamReference"}(s=e.JSCallResultType||(e.JSCallResultType={})),e.jsCallDispatcher={findJSFunction:E,disposeJSObjectReferenceById:w,invokeJSFromDotNet:(e,t,n,r)=>{const o=D(E(e,r).apply(null,m(t)),n);return null==o?null:A(o)},beginInvokeJSFromDotNet:(e,t,n,r,o)=>{const a=new Promise((e=>{e(E(t,o).apply(null,m(n)))}));e&&a.then((t=>g().endInvokeJSFromDotNet(e,!0,A([e,!0,D(t,r)]))),(t=>g().endInvokeJSFromDotNet(e,!1,JSON.stringify([e,!1,y(t)]))))},endInvokeDotNetFromJS:(e,t,n)=>{const r=t?m(n):new Error(n);b(parseInt(e),t,r)},receiveByteArray:(e,t)=>{n.set(e,t)}};class I{constructor(e){this._id=e}invokeMethod(e,...t){return p(null,e,this._id,t)}invokeMethodAsync(e,...t){return v(null,e,this._id,t)}dispose(){v(null,"__Dispose",this._id,null).catch((e=>console.error(e)))}serializeAsArg(){return{__dotNetObject:this._id}}}const S="__byte[]";function D(e,t){switch(t){case s.Default:return e;case s.JSObjectReference:return f(e);case s.JSStreamReference:return h(e);default:throw new Error(`Invalid JS call result type '${t}'.`)}}d((function(e,t){if(t&&"object"==typeof t){if(t.hasOwnProperty("__dotNetObject"))return new I(t.__dotNetObject);if(t.hasOwnProperty(o)){const e=t.__jsObjectId,n=i[e];if(n)return n.getWrappedObject();throw new Error(`JS object instance with Id '${e}' does not exist. It may have been disposed.`)}if(t.hasOwnProperty(S)){const e=t["__byte[]"],r=n.get(e);if(void 0===r)throw new Error(`Byte array index '${e}' does not exist.`);return r}}return t}));let C=0;function A(e){return C=0,JSON.stringify(e,T)}function T(e,t){if(t instanceof I)return t.serializeAsArg();if(t instanceof Uint8Array){u.sendByteArray(C,t);const e={[S]:C};return C++,e}return t}}(e||(e={})),function(e){e[e.prependFrame=1]="prependFrame",e[e.removeFrame=2]="removeFrame",e[e.setAttribute=3]="setAttribute",e[e.removeAttribute=4]="removeAttribute",e[e.updateText=5]="updateText",e[e.stepIn=6]="stepIn",e[e.stepOut=7]="stepOut",e[e.updateMarkup=8]="updateMarkup",e[e.permutationListEntry=9]="permutationListEntry",e[e.permutationListEnd=10]="permutationListEnd"}(t||(t={})),function(e){e[e.element=1]="element",e[e.text=2]="text",e[e.attribute=3]="attribute",e[e.component=4]="component",e[e.region=5]="region",e[e.elementReferenceCapture=6]="elementReferenceCapture",e[e.markup=8]="markup"}(n||(n={}));class r{constructor(e,t){this.componentId=e,this.fieldValue=t}static fromEvent(e,t){const n=t.target;if(n instanceof Element){const t=function(e){return e instanceof HTMLInputElement?e.type&&"checkbox"===e.type.toLowerCase()?{value:e.checked}:{value:e.value}:e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement?{value:e.value}:null}(n);if(t)return new r(e,t.value)}return null}}let o;function a(e,t){if(!o)throw new Error("eventDispatcher not initialized. Call 'setEventDispatcher' to configure it.");o(e,t)}const i=new Map,s=new Map,c={createEventArgs:()=>({})},l=[];function u(e){return i.get(e)}function d(e){const t=i.get(e);return(null==t?void 0:t.browserEventName)||e}function f(e,t){e.forEach((e=>i.set(e,t)))}function h(e){const t=[];for(let n=0;ne.selected)).map((e=>e.value))}}return{value:function(e){return!!e&&"INPUT"===e.tagName&&"checkbox"===e.getAttribute("type")}(t)?!!t.checked:t.value}}}),f(["copy","cut","paste"],c),f(["drag","dragend","dragenter","dragleave","dragover","dragstart","drop"],{createEventArgs:e=>{return{...m(t=e),dataTransfer:t.dataTransfer?{dropEffect:t.dataTransfer.dropEffect,effectAllowed:t.dataTransfer.effectAllowed,files:Array.from(t.dataTransfer.files).map((e=>e.name)),items:Array.from(t.dataTransfer.items).map((e=>({kind:e.kind,type:e.type}))),types:t.dataTransfer.types}:null};var t}}),f(["focus","blur","focusin","focusout"],c),f(["keydown","keyup","keypress"],{createEventArgs:e=>{return{key:(t=e).key,code:t.code,location:t.location,repeat:t.repeat,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey};var t}}),f(["contextmenu","click","mouseover","mouseout","mousemove","mousedown","mouseup","dblclick"],{createEventArgs:e=>m(e)}),f(["error"],{createEventArgs:e=>{return{message:(t=e).message,filename:t.filename,lineno:t.lineno,colno:t.colno};var t}}),f(["loadstart","timeout","abort","load","loadend","progress"],{createEventArgs:e=>{return{lengthComputable:(t=e).lengthComputable,loaded:t.loaded,total:t.total};var t}}),f(["touchcancel","touchend","touchmove","touchenter","touchleave","touchstart"],{createEventArgs:e=>{return{detail:(t=e).detail,touches:h(t.touches),targetTouches:h(t.targetTouches),changedTouches:h(t.changedTouches),ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,type:t.type};var t}}),f(["gotpointercapture","lostpointercapture","pointercancel","pointerdown","pointerenter","pointerleave","pointermove","pointerout","pointerover","pointerup"],{createEventArgs:e=>{return{...m(t=e),pointerId:t.pointerId,width:t.width,height:t.height,pressure:t.pressure,tiltX:t.tiltX,tiltY:t.tiltY,pointerType:t.pointerType,isPrimary:t.isPrimary};var t}}),f(["wheel","mousewheel"],{createEventArgs:e=>{return{...m(t=e),deltaX:t.deltaX,deltaY:t.deltaY,deltaZ:t.deltaZ,deltaMode:t.deltaMode};var t}}),f(["toggle"],c);const p=["date","datetime-local","month","time","week"],v=I(["abort","blur","change","error","focus","load","loadend","loadstart","mouseenter","mouseleave","progress","reset","scroll","submit","unload","toggle","DOMNodeInsertedIntoDocument","DOMNodeRemovedFromDocument"]),g={submit:!0},b=I(["click","dblclick","mousedown","mousemove","mouseup"]);class y{constructor(e){this.browserRendererId=e,this.afterClickCallbacks=[];const t=++y.nextEventDelegatorId;this.eventsCollectionKey=`_blazorEvents_${t}`,this.eventInfoStore=new E(this.onGlobalEvent.bind(this))}setListener(e,t,n,r){const o=this.getEventHandlerInfosForElement(e,!0),a=o.getHandler(t);if(a)this.eventInfoStore.update(a.eventHandlerId,n);else{const a={element:e,eventName:t,eventHandlerId:n,renderingComponentId:r};this.eventInfoStore.add(a),o.setHandler(t,a)}}getHandler(e){return this.eventInfoStore.get(e)}removeListener(e){const t=this.eventInfoStore.remove(e);if(t){const e=t.element,n=this.getEventHandlerInfosForElement(e,!1);n&&n.removeHandler(t.eventName)}}notifyAfterClick(e){this.afterClickCallbacks.push(e),this.eventInfoStore.addGlobalListener("click")}setStopPropagation(e,t,n){this.getEventHandlerInfosForElement(e,!0).stopPropagation(t,n)}setPreventDefault(e,t,n){this.getEventHandlerInfosForElement(e,!0).preventDefault(t,n)}onGlobalEvent(e){if(!(e.target instanceof Element))return;this.dispatchGlobalEventToAllElements(e.type,e);const t=(n=e.type,s.get(n));var n;t&&t.forEach((t=>this.dispatchGlobalEventToAllElements(t,e))),"click"===e.type&&this.afterClickCallbacks.forEach((t=>t(e)))}dispatchGlobalEventToAllElements(e,t){let n=t.target,o=null,i=!1;const s=v.hasOwnProperty(e);let c=!1;for(;n;){const f=this.getEventHandlerInfosForElement(n,!1);if(f){const s=f.getHandler(e);if(s&&(l=n,d=t.type,!((l instanceof HTMLButtonElement||l instanceof HTMLInputElement||l instanceof HTMLTextAreaElement||l instanceof HTMLSelectElement)&&b.hasOwnProperty(d)&&l.disabled))){if(!i){const n=u(e);o=(null==n?void 0:n.createEventArgs)?n.createEventArgs(t):{},i=!0}g.hasOwnProperty(t.type)&&t.preventDefault(),a({browserRendererId:this.browserRendererId,eventHandlerId:s.eventHandlerId,eventName:e,eventFieldInfo:r.fromEvent(s.renderingComponentId,t)},o)}f.stopPropagation(e)&&(c=!0),f.preventDefault(e)&&t.preventDefault()}n=s||c?null:n.parentElement}var l,d}getEventHandlerInfosForElement(e,t){return e.hasOwnProperty(this.eventsCollectionKey)?e[this.eventsCollectionKey]:t?e[this.eventsCollectionKey]=new w:null}}y.nextEventDelegatorId=0;class E{constructor(e){this.globalListener=e,this.infosByEventHandlerId={},this.countByEventName={},l.push(this.handleEventNameAliasAdded.bind(this))}add(e){if(this.infosByEventHandlerId[e.eventHandlerId])throw new Error(`Event ${e.eventHandlerId} is already tracked`);this.infosByEventHandlerId[e.eventHandlerId]=e,this.addGlobalListener(e.eventName)}get(e){return this.infosByEventHandlerId[e]}addGlobalListener(e){if(e=d(e),this.countByEventName.hasOwnProperty(e))this.countByEventName[e]++;else{this.countByEventName[e]=1;const t=v.hasOwnProperty(e);document.addEventListener(e,this.globalListener,t)}}update(e,t){if(this.infosByEventHandlerId.hasOwnProperty(t))throw new Error(`Event ${t} is already tracked`);const n=this.infosByEventHandlerId[e];delete this.infosByEventHandlerId[e],n.eventHandlerId=t,this.infosByEventHandlerId[t]=n}remove(e){const t=this.infosByEventHandlerId[e];if(t){delete this.infosByEventHandlerId[e];const n=d(t.eventName);0==--this.countByEventName[n]&&(delete this.countByEventName[n],document.removeEventListener(n,this.globalListener))}return t}handleEventNameAliasAdded(e,t){if(this.countByEventName.hasOwnProperty(e)){const n=this.countByEventName[e];delete this.countByEventName[e],document.removeEventListener(e,this.globalListener),this.addGlobalListener(t),this.countByEventName[t]+=n-1}}}class w{constructor(){this.handlers={},this.preventDefaultFlags=null,this.stopPropagationFlags=null}getHandler(e){return this.handlers.hasOwnProperty(e)?this.handlers[e]:null}setHandler(e,t){this.handlers[e]=t}removeHandler(e){delete this.handlers[e]}preventDefault(e,t){return void 0!==t&&(this.preventDefaultFlags=this.preventDefaultFlags||{},this.preventDefaultFlags[e]=t),!!this.preventDefaultFlags&&this.preventDefaultFlags[e]}stopPropagation(e,t){return void 0!==t&&(this.stopPropagationFlags=this.stopPropagationFlags||{},this.stopPropagationFlags[e]=t),!!this.stopPropagationFlags&&this.stopPropagationFlags[e]}}function I(e){const t={};return e.forEach((e=>{t[e]=!0})),t}const S=P("_blazorLogicalChildren"),D=P("_blazorLogicalParent"),C=P("_blazorLogicalEnd");function A(e,t){if(e.childNodes.length>0&&!t)throw new Error("New logical elements must start empty, or allowExistingContents must be true");return S in e||(e[S]=[]),e}function T(e,t){const n=document.createComment("!");return N(n,e,t),n}function N(e,t,n){const r=e;if(e instanceof Comment&&O(r)&&O(r).length>0)throw new Error("Not implemented: inserting non-empty logical container");if(R(r))throw new Error("Not implemented: moving existing logical children");const o=O(t);if(n0;)k(n,0)}const r=n;r.parentNode.removeChild(r)}function R(e){return e[D]||null}function F(e,t){return O(e)[t]}function _(e){var t=L(e);return"http://www.w3.org/2000/svg"===t.namespaceURI&&"foreignObject"!==t.tagName}function O(e){return e[S]}function x(e,t){const n=O(e);t.forEach((e=>{e.moveRangeStart=n[e.fromSiblingIndex],e.moveRangeEnd=M(e.moveRangeStart)})),t.forEach((t=>{const r=t.moveToBeforeMarker=document.createComment("marker"),o=n[t.toSiblingIndex+1];o?o.parentNode.insertBefore(r,o):H(r,e)})),t.forEach((e=>{const t=e.moveToBeforeMarker,n=t.parentNode,r=e.moveRangeStart,o=e.moveRangeEnd;let a=r;for(;a;){const e=a.nextSibling;if(n.insertBefore(a,t),a===o)break;a=e}n.removeChild(t)})),t.forEach((e=>{n[e.toSiblingIndex]=e.moveRangeStart}))}function L(e){if(e instanceof Element)return e;if(e instanceof Comment)return e.parentNode;throw new Error("Not a valid logical element")}function B(e){const t=O(R(e));return t[Array.prototype.indexOf.call(t,e)+1]||null}function H(e,t){if(t instanceof Element)t.appendChild(e);else{if(!(t instanceof Comment))throw new Error(`Cannot append node because the parent is not a valid logical element. Parent: ${t}`);{const n=B(t);n?n.parentNode.insertBefore(e,n):H(e,R(t))}}}function M(e){if(e instanceof Element)return e;const t=B(e);if(t)return t.previousSibling;{const t=R(e);return t instanceof Element?t.lastChild:M(t)}}function P(e){return"function"==typeof Symbol?Symbol():e}function U(e){return`_bl_${e}`}e.attachReviver(((e,t)=>t&&"object"==typeof t&&t.hasOwnProperty("__internalId")&&"string"==typeof t.__internalId?function(e){const t=`[${U(e)}]`;return document.querySelector(t)}(t.__internalId):t));const j="_blazorDeferredValue",J=document.createElement("template"),$=document.createElementNS("http://www.w3.org/2000/svg","g"),z={},K="__internal_",V="preventDefault_",X="stopPropagation_";class Y{constructor(e){this.childComponentLocations={},this.eventDelegator=new y(e),this.eventDelegator.notifyAfterClick((e=>{if(!ne)return;if(0!==e.button||function(e){return e.ctrlKey||e.shiftKey||e.altKey||e.metaKey}(e))return;if(e.defaultPrevented)return;const t=function(e){const t=!window._blazorDisableComposedPath&&e.composedPath&&e.composedPath();if(t){for(let e=0;ece(!1))))},enableNavigationInterception:function(){ne=!0},navigateTo:ie,getBaseURI:()=>document.baseURI,getLocationHref:()=>location.href};function ie(e,t,n=!1){const r=ue(e),o=t instanceof Object?t:{forceLoad:t,replaceHistoryEntry:n};!o.forceLoad&&fe(r)?se(r,!1,o.replaceHistoryEntry):function(e,t){if(location.href===e){const t=e+"?";history.replaceState(null,"",t),location.replace(e)}else t?location.replace(e):location.href=e}(e,o.replaceHistoryEntry)}function se(e,t,n){te=!0,n?history.replaceState(null,"",e):history.pushState(null,"",e),ce(t)}async function ce(e){oe&&await oe(location.href,e)}let le;function ue(e){return le=le||document.createElement("a"),le.href=e,le.href}function de(e,t){return e?e.tagName===t?e:de(e.parentElement,t):null}function fe(e){const t=(n=document.baseURI).substr(0,n.lastIndexOf("/")+1);var n;return e.startsWith(t)}const he={init:function(e,t,n,r=50){const o=pe(t);(o||document.documentElement).style.overflowAnchor="none";const a=new IntersectionObserver((function(r){r.forEach((r=>{var o;if(!r.isIntersecting)return;const a=t.getBoundingClientRect(),i=n.getBoundingClientRect().top-a.bottom,s=null===(o=r.rootBounds)||void 0===o?void 0:o.height;r.target===t?e.invokeMethodAsync("OnSpacerBeforeVisible",r.intersectionRect.top-r.boundingClientRect.top,i,s):r.target===n&&n.offsetHeight>0&&e.invokeMethodAsync("OnSpacerAfterVisible",r.boundingClientRect.bottom-r.intersectionRect.bottom,i,s)}))}),{root:o,rootMargin:`${r}px`});a.observe(t),a.observe(n);const i=c(t),s=c(n);function c(e){const t=new MutationObserver((()=>{a.unobserve(e),a.observe(e)}));return t.observe(e,{attributes:!0}),t}me[e._id]={intersectionObserver:a,mutationObserverBefore:i,mutationObserverAfter:s}},dispose:function(e){const t=me[e._id];t&&(t.intersectionObserver.disconnect(),t.mutationObserverBefore.disconnect(),t.mutationObserverAfter.disconnect(),e.dispose(),delete me[e._id])}},me={};function pe(e){return e?"visible"!==getComputedStyle(e).overflowY?e:pe(e.parentElement):null}function ve(e,t){const n=e._blazorFilesById[t];if(!n)throw new Error(`There is no file with ID ${t}. The file list may have changed.`);return n}const ge={navigateTo:ie,registerCustomEventType:function(e,t){if(!t)throw new Error("The options parameter is required.");if(i.has(e))throw new Error(`The event '${e}' is already registered.`);if(t.browserEventName){const n=s.get(t.browserEventName);n?n.push(e):s.set(t.browserEventName,[e]),l.forEach((n=>n(e,t.browserEventName)))}i.set(e,t)},_internal:{navigationManager:ae,domWrapper:{focus:function(e,t){if(!(e instanceof HTMLElement))throw new Error("Unable to focus an invalid element.");e.focus({preventScroll:t})},focusBySelector:function(e){const t=document.querySelector(e);t&&(t.hasAttribute("tabindex")||(t.tabIndex=-1),t.focus())}},Virtualize:he,PageTitle:{getAndRemoveExistingTitle:function(){var e;const t=document.getElementsByTagName("title");if(0===t.length)return null;let n=null;for(let r=t.length-1;r>=0;r--){const o=t[r],a=o.previousSibling;a instanceof Comment&&null!==R(a)||(null===n&&(n=o.textContent),null===(e=o.parentNode)||void 0===e||e.removeChild(o))}return n}},InputFile:{init:function(e,t){t._blazorInputFileNextFileId=0,t.addEventListener("click",(function(){t.value=""})),t.addEventListener("change",(function(){t._blazorFilesById={};const n=Array.prototype.map.call(t.files,(function(e){const n={id:++t._blazorInputFileNextFileId,lastModified:new Date(e.lastModified).toISOString(),name:e.name,size:e.size,contentType:e.type,readPromise:void 0,arrayBuffer:void 0,blob:e};return t._blazorFilesById[n.id]=n,n}));e.invokeMethodAsync("NotifyChange",n)}))},toImageFile:async function(e,t,n,r,o){const a=ve(e,t),i=await new Promise((function(e){const t=new Image;t.onload=function(){e(t)},t.src=URL.createObjectURL(a.blob)})),s=await new Promise((function(e){var t;const a=Math.min(1,r/i.width),s=Math.min(1,o/i.height),c=Math.min(a,s),l=document.createElement("canvas");l.width=Math.round(i.width*c),l.height=Math.round(i.height*c),null===(t=l.getContext("2d"))||void 0===t||t.drawImage(i,0,0,l.width,l.height),l.toBlob(e,n)})),c={id:++e._blazorInputFileNextFileId,lastModified:a.lastModified,name:a.name,size:(null==s?void 0:s.size)||0,contentType:n,blob:s||a.blob};return e._blazorFilesById[c.id]=c,c},readFileData:async function(e,t){return ve(e,t).blob}},getJSDataStreamChunk:async function(e,t,n){return e instanceof Blob?await async function(e,t,n){const r=e.slice(t,t+n),o=await r.arrayBuffer();return new Uint8Array(o)}(e,t,n):function(e,t,n){return new Uint8Array(e.buffer,e.byteOffset+t,n)}(e,t,n)}}};window.Blazor=ge;let be=!1;const ye="function"==typeof TextDecoder?new TextDecoder("utf-8"):null,Ee=ye?ye.decode.bind(ye):function(e){let t=0;const n=e.length,r=[],o=[];for(;t65535&&(o-=65536,r.push(o>>>10&1023|55296),o=56320|1023&o),r.push(o)}r.length>1024&&(o.push(String.fromCharCode.apply(null,r)),r.length=0)}return o.push(String.fromCharCode.apply(null,r)),o.join("")},we=Math.pow(2,32),Ie=Math.pow(2,21)-1;function Se(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24}function De(e,t){return e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24>>>0)}function Ce(e,t){const n=De(e,t+4);if(n>Ie)throw new Error(`Cannot read uint64 with high order part ${n}, because the result would exceed Number.MAX_SAFE_INTEGER.`);return n*we+De(e,t)}class Ae{constructor(e){this.batchData=e;const t=new Re(e);this.arrayRangeReader=new Fe(e),this.arrayBuilderSegmentReader=new _e(e),this.diffReader=new Te(e),this.editReader=new Ne(e,t),this.frameReader=new ke(e,t)}updatedComponents(){return Se(this.batchData,this.batchData.length-20)}referenceFrames(){return Se(this.batchData,this.batchData.length-16)}disposedComponentIds(){return Se(this.batchData,this.batchData.length-12)}disposedEventHandlerIds(){return Se(this.batchData,this.batchData.length-8)}updatedComponentsEntry(e,t){const n=e+4*t;return Se(this.batchData,n)}referenceFramesEntry(e,t){return e+20*t}disposedComponentIdsEntry(e,t){const n=e+4*t;return Se(this.batchData,n)}disposedEventHandlerIdsEntry(e,t){const n=e+8*t;return Ce(this.batchData,n)}}class Te{constructor(e){this.batchDataUint8=e}componentId(e){return Se(this.batchDataUint8,e)}edits(e){return e+4}editsEntry(e,t){return e+16*t}}class Ne{constructor(e,t){this.batchDataUint8=e,this.stringReader=t}editType(e){return Se(this.batchDataUint8,e)}siblingIndex(e){return Se(this.batchDataUint8,e+4)}newTreeIndex(e){return Se(this.batchDataUint8,e+8)}moveToSiblingIndex(e){return Se(this.batchDataUint8,e+8)}removedAttributeName(e){const t=Se(this.batchDataUint8,e+12);return this.stringReader.readString(t)}}class ke{constructor(e,t){this.batchDataUint8=e,this.stringReader=t}frameType(e){return Se(this.batchDataUint8,e)}subtreeLength(e){return Se(this.batchDataUint8,e+4)}elementReferenceCaptureId(e){const t=Se(this.batchDataUint8,e+4);return this.stringReader.readString(t)}componentId(e){return Se(this.batchDataUint8,e+8)}elementName(e){const t=Se(this.batchDataUint8,e+8);return this.stringReader.readString(t)}textContent(e){const t=Se(this.batchDataUint8,e+4);return this.stringReader.readString(t)}markupContent(e){const t=Se(this.batchDataUint8,e+4);return this.stringReader.readString(t)}attributeName(e){const t=Se(this.batchDataUint8,e+4);return this.stringReader.readString(t)}attributeValue(e){const t=Se(this.batchDataUint8,e+8);return this.stringReader.readString(t)}attributeEventHandlerId(e){return Ce(this.batchDataUint8,e+12)}}class Re{constructor(e){this.batchDataUint8=e,this.stringTableStartIndex=Se(e,e.length-4)}readString(e){if(-1===e)return null;{const n=Se(this.batchDataUint8,this.stringTableStartIndex+4*e),r=function(e,t){let n=0,r=0;for(let o=0;o<4;o++){const a=e[t+o];if(n|=(127&a)<{!function(e,t,n){const r="::after";let o=!1;if(e.endsWith(r))e=e.slice(0,-r.length),o=!0;else if(e.endsWith("::before"))throw new Error("The '::before' selector is not supported.");const a=document.querySelector(e);if(!a)throw new Error(`Could not find any element matching selector '${e}'.`);!function(e,t,n,r){let o=ee[0];o||(o=ee[0]=new Y(0)),o.attachRootComponentToLogicalElement(n,t,r)}(0,A(a,!0),t,o)}(t,e)},RenderBatch:(e,t)=>{try{const n=Je(t);(function(e,t){const n=ee[0];if(!n)throw new Error("There is no browser renderer with ID 0.");const r=t.arrayRangeReader,o=t.updatedComponents(),a=r.values(o),i=r.count(o),s=t.referenceFrames(),c=r.values(s),l=t.diffReader;for(let e=0;e{xe=!0,console.error(`${e}\n${t}`),async function(){let e=document.querySelector("#blazor-error-ui");e&&(e.style.display="block"),be||(be=!0,document.querySelectorAll("#blazor-error-ui .reload").forEach((e=>{e.onclick=function(e){location.reload(),e.preventDefault()}})),document.querySelectorAll("#blazor-error-ui .dismiss").forEach((e=>{e.onclick=function(e){const t=document.querySelector("#blazor-error-ui");t&&(t.style.display="none"),e.preventDefault()}})))}()},BeginInvokeJS:e.jsCallDispatcher.beginInvokeJSFromDotNet,EndInvokeDotNet:e.jsCallDispatcher.endInvokeDotNetFromJS,SendByteArrayToJS:je,Navigate:ae.navigateTo};window.external.receiveMessage((e=>{const n=function(e){if(xe||!e||!e.startsWith(Oe))return null;const t=e.substring(Oe.length),[n,...r]=JSON.parse(t);return{messageType:n,args:r}}(e);if(n){if(!t.hasOwnProperty(n.messageType))throw new Error(`Unsupported IPC message type '${n.messageType}'`);t[n.messageType].apply(null,n.args)}}))}(),e.attachDispatcher({beginInvokeDotNetFromJS:Be,endInvokeJSFromDotNet:He,sendByteArray:Me}),ae.enableNavigationInterception(),ae.listenForNavigationEvents(Pe),Ue("AttachPage",ae.getBaseURI(),ae.getLocationHref())}o=function(e,t){Ue("DispatchBrowserEvent",e,t)},ge.start=ze,document&&document.currentScript&&"false"!==document.currentScript.getAttribute("autostart")&&ze()})(); \ No newline at end of file From c8f9e100d53897223e2b81240fd777837c881dd1 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 20 Jul 2021 09:34:03 -0700 Subject: [PATCH 2/2] Use Dispose instead of DisposeAsync to clear hot reload state Partial fix for https://github.com/dotnet/aspnetcore/issues/34414 --- .../Components/src/RenderTree/Renderer.cs | 57 ++++++++++++------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/src/Components/Components/src/RenderTree/Renderer.cs b/src/Components/Components/src/RenderTree/Renderer.cs index 8351d84e1de0..d0a120b5c800 100644 --- a/src/Components/Components/src/RenderTree/Renderer.cs +++ b/src/Components/Components/src/RenderTree/Renderer.cs @@ -42,6 +42,7 @@ public abstract partial class Renderer : IDisposable, IAsyncDisposable private bool _isBatchInProgress; private ulong _lastEventHandlerId; private List? _pendingTasks; + private Task? _disposeTask; /// /// Allows the caller to handle exceptions from the SynchronizationContext when one is available. @@ -955,26 +956,10 @@ private void HandleExceptionViaErrorBoundary(Exception error, ComponentState? er /// Releases all resources currently used by this instance. /// /// if this method is being invoked by , otherwise . - protected virtual void Dispose(bool disposing) => DisposeAsync().AsTask().GetAwaiter().GetResult(); - - /// - /// Releases all resources currently used by this instance. - /// - public void Dispose() - { - Dispose(disposing: true); - } - - /// - public async ValueTask DisposeAsync() + protected virtual void Dispose(bool disposing) { - if (Disposed) - { - return; - } - Disposed = true; - + if (TestableMetadataUpdate.IsSupported) { HotReloadManager.OnDeltaApplied -= RenderRootComponentsOnHotReload; @@ -1032,7 +1017,7 @@ public async ValueTask DisposeAsync() if (asyncDisposables?.Count >= 1) { - await HandleAsyncExceptions(asyncDisposables); + _disposeTask = HandleAsyncExceptions(asyncDisposables); } async Task HandleAsyncExceptions(List tasks) @@ -1066,5 +1051,39 @@ void NotifyExceptions(List exceptions) } } } + + /// + /// Releases all resources currently used by this instance. + /// + public void Dispose() + { + Dispose(disposing: true); + } + + /// + public async ValueTask DisposeAsync() + { + if (Disposed) + { + return; + } + + if (_disposeTask != null) + { + await _disposeTask; + } + else + { + Dispose(); + if (_disposeTask != null) + { + await _disposeTask; + } + else + { + await default(ValueTask); + } + } + } } }