Skip to content
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

[Bug]: Switching between rich text components to fast, causes Microsoft.JSInterop.JSException #5519

Open
BpKlomp opened this issue May 22, 2024 · 7 comments
Assignees
Labels
Type: Bug 🐞 Something isn't working
Projects
Milestone

Comments

@BpKlomp
Copy link

BpKlomp commented May 22, 2024

Blazorise Version

1.5.1

What Blazorise provider are you running on?

Bootstrap5

Link to minimal reproduction or a simple code snippet

Make two components that have one or more rich text editor components.
Create a way to switch between te two.
If you switch fast enough the eroor will be displayed

Steps to reproduce

//

What is expected?

It should not cause an error

What is actually happening?

In richtextedit.json line 120, editorRef is null before it's called. Because you switch before it loaded fully, it causes an error.

Microsoft.JSInterop.JSException: Cannot read properties of null (reading 'quill')
TypeError: Cannot read properties of null (reading 'quill')
at Module.setReadOnly (https://localhost:7207/_content/Blazorise.RichTextEdit/richtextedit.js?v=1.5.1.0:123:30)
at https://localhost:7207/_framework/blazor.server.js:1:3506
at new Promise ()
at Ft.beginInvokeJSFromDotNet (https://localhost:7207/_framework/blazor.server.js:1:3480)
at Ft._invokeClientMethod (https://localhost:7207/_framework/blazor.server.js:1:75072)
at Ft._processIncomingData (https://localhost:7207/_framework/blazor.server.js:1:72696)
at Ft.connection.onreceive (https://localhost:7207/_framework/blazor.server.js:1:67009)
at i.onmessage (https://localhost:7207/_framework/blazor.server.js:1:51322)
at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
at Microsoft.JSInterop.JSObjectReferenceExtensions.InvokeVoidAsync(IJSObjectReference jsObjectReference, String identifier, Object[] args)
at Blazorise.Modules.BaseJSModule.InvokeSafeVoidAsync(String identifier, Object[] args)
at Blazorise.RichTextEdit.RichTextEdit.<>c__DisplayClass15_0.<b__1>d.MoveNext()

What browsers do you see the problem on?

Microsoft Edge

Any additional comments?

This bug has been happening for multiple versions of blazorize

@BpKlomp BpKlomp added the Type: Bug 🐞 Something isn't working label May 22, 2024
@stsrki
Copy link
Collaborator

stsrki commented May 22, 2024

Can I ask you to create a simple reproducible?

@BpKlomp
Copy link
Author

BpKlomp commented May 22, 2024

I will try to. After this message I started. The bug is not as easy to reproduce as I thought it would be. Something to do with the way we switch between components with some delay somewhere. Should have something soon

@stsrki stsrki self-assigned this May 22, 2024
@BpKlomp
Copy link
Author

BpKlomp commented May 22, 2024

I managed to track down what the issue was in my code. Though I did make a basic project to reproduce. Some stuff is probably unnecessary https://github.com/BpKlomp/RichTextEditBug/tree/main

If you run the project, you just have to switch between the two buttons a couple of times and it will happen quite consistently. The issue happens because of the extra state changes after switching. Its bad code, so maybe it's not worth fixing on your end. (index.razor line 37-40)

@stsrki
Copy link
Collaborator

stsrki commented May 22, 2024

It usually happens to be the users code at fault :)

Yeah, I think this is not so much of a Blazorise issue. If you agree, I will close it.

@BpKlomp
Copy link
Author

BpKlomp commented May 22, 2024

The issue still exists somewhere, but it might be Blazor itself. Just the way it is caused on my end can be fixed. There is still scenarios where this will happen to others, for legitimate reasons.

Probably for now its fine to close it and if someone has the same issue they can reopen it.

@stsrki stsrki closed this as completed May 22, 2024
@BpKlomp
Copy link
Author

BpKlomp commented May 31, 2024

It seems like the issue is more likely than I first thought. The specific code we had in place, just caused this relatively often. But there is more cases where this or a related error happens (System.NullReferenceException at Blazorise.Extensions.ObjectExtensions+d__1.MoveNex)

The problem appears whenever you trigger a StateHasChanged during the loading/unloading of the rich text editor. This could be in a different function running on the side to the one that you're using to switch objects.

@stsrki stsrki reopened this May 31, 2024
@stsrki stsrki added this to 🔙 Backlog in Support via automation May 31, 2024
@stsrki stsrki added this to the 1.5 support milestone May 31, 2024
@stsrki
Copy link
Collaborator

stsrki commented May 31, 2024

I will try and see if we can improve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug 🐞 Something isn't working
Projects
Support
  
🔙 Backlog
Development

No branches or pull requests

2 participants