-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Unpredictable No element is currently associated with component {ComponentId} #5592
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
Comments
This isn't a known issue, so if you have any way to reproduce it, we'd definitely want to fix it. I can't really take any action on this right now because I've never seen this happen so have no clue about what might cause it. It's possibly something unique to your app, but we'd know more if there was a repro.
Can you clarify this point? Is there some code sample you could post that shows it with the |
Thanks for confirming! It sounds like this is not a bug, but if you have a code sample to share that triggers the error, I could give a more precise answer. |
Issue is actually still unresolved, on unpredictable intervals I get the following error message:
I wonder if it's possible to debug this sort of stuff. because I currently have no idea what component has the id Codebase is pretty large, but I can do a VS Live Share if you'd like. |
@vertonghenb For us to investigate we're going to need steps to reproduce the issue. Is there a way you can trim down your app to just the code that causes the problem? |
@danroth27 I'd love to give some reproduction steps but unfortunately I have no idea how to reproduce the issue, sometimes the error hardly shows up, sometimes it does more frequently. It happends after an async (await) load of data and navigating to another component the components takes a delegate functions |
@SteveSandersonMS Might this be related at all to dotnet/blazor#1651? |
@danroth27 I don't think so. This issue implies that somehow it's possible to re-render a component after it's already been disposed (or that the initial attempt to add the component failed on the JS side, though I don't see how). That shouldn't be possible, and we have a test to back this up (that after disposal, re-render attempts will be skipped), but apparently there is some unanticipated timing-based way of doing that. If we had a repro I'm sure it would be quick to track down, but without one it's difficult to even start looking. |
@SteveSandersonMS I invited you to the Repository where the App is hosted, since the error is all over the place, I can't pin-point it. At a certain point I even changed every async code with sync.(not anymore though) then the error doesn't show up anymore so I believe it's related to async and timing. The instructions to reproduce the error are in the readme of the repo. |
@SteveSandersonMS , related to dotnet/blazor#1666 ? |
@SteveSandersonMS @danroth27 Task<List<T>> GetIndexAsync(string searchTerm, int take = 50); When the code is not async, the error never occurs, so I'm pretty confident it's a timing issue. Code that triggers this: @page "/customers"
@using Ecocolors.Domain.Models.Stakeholders
@inject ICustomerManager CustomerManager
@inject IFormHandler FormHandler
<MPage Title="Klanten" Icon=@EIcon.EC_Customer>
<Actions>
<MButton Icon=@EIcon.LA_Plus State=@EState.Success OnClick=@((e) =>FormHandler.ShowCreateForm<Forms.Mutate>()) />
</Actions>
<Body>
<MPortlet >
<Content>
<MToolBar SearchTerm="@_searchTerm" OnChanged="@OnSearchTermChange"/>
<MTable TItem="Customer" Items="@_customers" IsLoading="@_isLoading">
<Header>
<th>Actief</th>
<th>Nummer</th>
<th>BTW Nr.</th>
<th>Naam</th>
<th>Adres</th>
</Header>
<Row Context="customer">
<td><MEnabledBadge IsEnabled=@customer.Enabled /></td>
<td>@customer.Sequence</td>
<td>@customer.VATNumber</td>
<td><MLink Url=@($"customers/{customer.Id}") Text=@customer.Name /></td>
<td>@customer.Headquarter?.Address?.DisplayName</td>
</Row>
</MTable>
</Content>
</MPortlet>
</Body>
</MPage>
@functions{
private IReadOnlyList<Customer> _customers = new List<Customer>();
private bool _isLoading = true;
private string _searchTerm = string.Empty;
private int _amount = 50;
protected async override Task OnInitAsync()
{
_customers = await CustomerManager.GetIndexAsync(_searchTerm);
_isLoading = false;
}
private async Task OnSearchTermChange(string term)
{
if (_isLoading)
return;
_isLoading = true;
_searchTerm = term;
StateHasChanged();
_customers = await CustomerManager.GetIndexAsync(_searchTerm, _amount);
_isLoading = false;
StateHasChanged();
}
} On The Server:
On The Client:
|
@danroth27 After a month of struggling... I finally reproduced the issue on a smaller app. It doesn't look that bad in the smaller application but bear in mind that on a more complex application the issue is thrown a lot more and makes Razor Components highly unstable and basically unusable(you don't want the user to have to refresh the app every 5 minutes). The repository where the app is hosted can be found here: Version: 2 pages If you start clicking around in the navigating bar (like a maniac, I really mean like a maniac) navigating between multiple pages (even using the fetch data and counter pages, it can take up to 20-30+ navigations). You'll get the following error messages in the console, then the user has to refresh the browser.
If the data fetching logic is synchronous the error is never presented, but gives a rather annoying user experience. |
I updated my server side blazor app from 0.6 to 0.7 today, and have started to get loads of the stated error: "Uncaught Error: No element is currently associated with component". It's happening all over the app (I get hundreds of error messages). Also, changes to the dom are now visually obvious, the page content flashes as it is replaced, whereas in 0.6 it updated smoothly. |
Also started to see this problem since the update to 0.7.0. Not noticed the DOM issues with redraw. It seems that once a page suffers from this issue there are 2 ways to resolve it. Navigate to another page within the application and back, or a full page refresh. I did think it was something to do with timing but it's not. This issue is happening on the most basic of pages.
As mentioned it seems to be async related. I have a navigation component included in the master layout which async loads data. |
We are also experiencing this suddenly after 0.7. It also is to do with an await in an after render async callback. It'll work a for a while, then suddenly one time the elementref is not set. And since you (apparently) can't even test an elementref to see if its good, it's tough to even work around. If you don't do something to prevent re-render after the error, it goes off into a loop, as above. |
Another +1 from the same team as Dean above, but on an unrelated Blazor project. I'd say this was occaisional in 0.6.0 and could never be pinned down but happens with regularity on 0.7.0 |
@aaronsmithuk , @TheRubble , @DeanRoddey , @MarkStega |
I think that this newer issue is probably the same underlying thing? https://github.com/aspnet/Blazor/issues/1700 The suggestion there is that maybe on after render is getting triggered too early sometimes, before elementrefs are set. |
@DeanRoddey There is no elementref involved in the codebase. |
Since multiple applications are having this issue, can we mark it as a bug? |
Sure. I've no doubt there's a real bug here. I strongly expect it will vanish when we deal with #5639 (though if it doesn't, obviously we'll have to track down the cause). |
I am getting this error as well. I have declared multiple components (entrypoints) in the Startup.cs:
I include them on different locations on the website. However, this makes this error appear. Only if I include every tag of all declared components, the error does not occur (It does at some point if navigation events take place, but in my case this isn't happening). May be this helps to track down the cause. |
i'm experiencing this in similar circumstances. i have a repro if that's useful - an app which breaks very quickly when run under SSR/razor components. i can share it but not publically |
I'm currently using a workaround - I have a custom version of blazor.server.js where the renderer gives up trying to apply the edit and just returns, rather than throwing an error which will break the websocket connection. this isn't suitable for production, since it still means that some component just doesn't update and you have to try the state change again, but it's ok for demos and prototyping |
Hello, I've got this error too, but I think the problem is another than discussed until now… We are developing a blazor version of our 3D product configuration application at the moment and we use xml3d to build the scene in html with blazor (works like a charm by the way :-) ). Here we define the required materials first and later we reference the materials in the geometries... at some point of the development we had the situation that some geometries were rendered with the wrong material or with no material... but the material elements where correct. So we hat a look how the material elements where changed while configuring (for example changing the color of the product). And I think what we saw is the underlying problem here: When we added a material that was not the last in the material list (we sorted the elements by their id), the DOM was correctly changed… BUT the "instances" where changed mixed up… example… < Material id="a" src="x"/> Then we add: Result: On the first look, that is correct… BUT the former material "c" was changed to "b" and a new element with id "c" was added (you can see this in dev mode of chrome)… and that was the problem! We fixed it by making sure that we only add new elements to the end and never remove elements (in this example a,c,b) and that works. But of course this only works in this special scenario and we have the lots of problems with "no elements etc." too, but I think this gives us an interesting hint, why the event handles stop working… Lets adapt the scenario from above to an other sample... < div onclick="handler (click component 1)">Product A< /div> now we remove product B and add Product C... then we expect that the html-element of product B is removed and a new element for product C is created… but that is not the case… it "updates" the existing element for product B to match the required element for product C. And in this case the event handler IS NOT updated to macht the event handler for product C... result: < div onclick="handler (click component 1)">Product A< /div> When you click on product C the server creates an exception "no element assigned to 2" because the sever "thinks" the element for product B (2) was removed and a new for product C (3) was created… but that is not the case. When you now create a button that toggles the rendering of the product list and click it to remove all elements and click it again to rerender the list, everything is working again… I hope this helps to get rid of this annoying bug… Carl |
@CobraCalle Your issue sounds unrelated to the one being originally reported here. I think your issue is that you need to preserve DOM element identity through edits because of the 3rd party library that's also interacting with the DOM. This requirement is handled by specifying |
You know, thinking about this just now as it was happening to me again... I wonder if it's as simple as just not reliably getting rid of element/component references when the things referenced go away. Given that, for us, it always happens after we invoke a modal, and then render those bits away when the modal is dismissed. The stuff is obviously gone, because it doesn't get drawn anymore and StateHasChanged has to be called to make that happen, but then we get the problem after that in certain subsequent popups. It's as though some internal refs to the things that got rendered away are still there. |
Ok it took a lot of elimination, but for me - I can replicate this Issue as soon as I inject a HttpClient in my page. I dont even have to use it. Just inject it: |
Further to this its actually when i simply Inject ANYTHING on the page. I created a skeleton class, injected it into my page, and I got the "No element is currently associated with component {id}" error. When I remove the inject, the page loads correctly again. (This is only on server side - client side blazor works fine). Which now has me very confused as for some reason the Template Server Side Project injects a service in the FetchData Page and its working fine. Same version of blazor and .net core... im stumped! |
I was just able to solve this (for my project anyway) by following the fantastic idea in this git: |
Seems to be fixed in Preview-2 |
I received this error because I was trying to @ inject the wrong type and this was the general error that was thrown instead of a relevant error relating to finding the service in the collection\container. This happened with 3.0.0-preview8.19405.7 Also when this occurred I could not step into client debugger since this is happening in @ inject |
Edited to remove the false-positives
Reproducable : https://github.com/aspnet/Blazor/issues/1412#issuecomment-439267547
Using Blazor Server Side
From time to time Blazor throws the following error:
No element is currently associated with component {ComponentId}
The error is always thrown on the first load after a
StateHasChanged
, if you hard refresh the page the error doesn't happen anymore.For me this is quite vague and it happends for no certain reason, only from time to time.
The text was updated successfully, but these errors were encountered: