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

Compatability with Blazor updating? #1

Open
HurricanKai opened this issue Jul 9, 2019 · 4 comments
Open

Compatability with Blazor updating? #1

HurricanKai opened this issue Jul 9, 2019 · 4 comments
Labels
bug Something isn't working

Comments

@HurricanKai
Copy link

Is this compatible with Blazor updating the DOM? Wouldn't that override all changes?
For example:

@page "/"
@inject BlazorQueryDOM DOM

<h1>@TestVal</h1>

@code {
    string TestVal = "TestA";

    protected override async Task OnAfterRenderAsync()
    {
      await DOM.Select("h1").Text("TestB");
      TestVal = "TestC"
    }
}

What will actually be displayed? (I'm not at home and I'm really interested into this, maybe you can answer, else I'll try it out later)

@kevinjpetersen
Copy link
Owner

Hey @HurricanKai, thanks for your concern/question!

I just tested this exact scenario, and you seem to be right that there is some weird things happening in cases like this. It seems that setting the content of an element after having the binded "TestVal", unbinds it and makes TestVal no longer display.

I'm gonna look into it to see if I can find a possible fix.

@kevinjpetersen kevinjpetersen added the bug Something isn't working label Jul 9, 2019
@CSBatchelor
Copy link

You'll definitely want to avoid modifying the DOM manually when using Blazor. In Blazor's JS Interop documentation it says as much.

Warning

The preceding example modifies the Document Object Model (DOM) directly for demonstration purposes only. Directly modifying the DOM with JavaScript isn't recommended in most scenarios because JavaScript can interfere with Blazor's change tracking.

Later in the documentation, it states that they would only recommend modifying an element if the element started out empty. That way Blazor doesn't try to diff it.

Perhaps moving forward, this package shouldn't support updating the DOM, and should only support getting data/information from the DOM, since Blazor is lacking in that regard.

@amazingalek
Copy link
Contributor

Perhaps moving forward, this package shouldn't support updating the DOM, and should only support getting data/information from the DOM, since Blazor is lacking in that regard.

I use this project specifically for DOM manipulation, as I'm making a Chrome extension with Blazor for manipulating web pages.

kevinjpetersen pushed a commit that referenced this issue May 1, 2021
@kevinjpetersen
Copy link
Owner

Perhaps moving forward, this package shouldn't support updating the DOM, and should only support getting data/information from the DOM, since Blazor is lacking in that regard.

I use this project specifically for DOM manipulation, as I'm making a Chrome extension with Blazor for manipulating web pages.

I can definitely see this use case as you just pointed out. Being able to manipulate DOM's easily in Chrome extensions is really powerful.

I do agree that supporting both scenarios would make a lot of sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants