-
Notifications
You must be signed in to change notification settings - Fork 62
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
- Server side blazor
- Similar code to the dragndrop example
- Getting the following error randomly on refresh (about 30%-50% of the time):
Unhandled exception rendering component: Could not find 'FileReaderComponent' in 'window'.
Error: Could not find 'FileReaderComponent' in 'window'.
The error occurs on: RegisterDropEventsAsync();
:
protected override async Task OnAfterRenderAsync()
{
labelFilesReference = fileReaderService.CreateReference(labelElement);
await labelFilesReference.RegisterDropEventsAsync();
}
I do have InitializeOnFirstCall
enabled, but I also tried this as well:
protected override async Task OnAfterRenderAsync()
{
await fileReaderService.EnsureInitializedAsync();
labelFilesReference = fileReaderService.CreateReference(labelElement);
await labelFilesReference.RegisterDropEventsAsync();
}
... and still received the error (same frequency). Adding Task.Delay did not help.
Retrying when it fails fixes the issue, which I think is probably evidence that there is a race condition here (which could mean the problem can only be replicated at very low latency e.g. local development).
This works:
protected override async Task OnAfterRenderAsync()
{
labelFilesReference = fileReaderService.CreateReference(labelElement);
try
{
await labelFilesReference.RegisterDropEventsAsync();
}
catch (JSException ex)
when (ex.Message.Contains("Could not find 'FileReaderComponent' in 'window'"))
{
// failed race condition, just try again
await labelFilesReference.RegisterDropEventsAsync();
}
}
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working