Closed AlbertSabate closed 1 month ago
If the web component exists in both pages, it is not dismounted and mounted again, it is the grace to maintain the state of it without being dismounted. This is implemented this way on purpose. This way the layout remains the same after browsing. If you need to dismount and mount it during navigation, you can use a key
based on the route
. When the key
change force the unmount/mounting. But by default, it's not dismounted on purpose.
In the case of a page without the same Web Component should unmount and mount again always.
@aralroca, this is yet unclear where the issue comes from. After more debug it does not seem to come from effects or unMount. It is for that I wrote a note "Pending to add a reproduction @AlbertSabate". Something is off with some code I'm currently debugging and trying to narrow it down. I will use this issue for me to track down tests I did and not to forget. Please ignore it until I can clarify the root issue.
From this code:
effect(() => {
console.log(
'Im here',
self.hasAttribute('tabindex'),
self,
);
if (!self.hasAttribute('tabindex')) {
self.setAttribute('tabindex', '0');
}
});
When loading the component for first time and second time seems something different.
@aralroca why the first time is an object and second an HTMLElement?
Interestingly, the first time appends properly the attr tabindex, but the second time no.
Confirmed unMount and effects it is working as expected.
From this code:
effect(() => { console.log( 'Im here', self.hasAttribute('tabindex'), self, ); if (!self.hasAttribute('tabindex')) { self.setAttribute('tabindex', '0'); } });
When loading the component for first time and second time seems something different.
@aralroca why the first time is an object and second an HTMLElement?
An object? Well, elements are objects, I guess it's something in DevTools that doesn't show it well, but you can use it as an element without problems, right?
I can use it, and it seems properly selecting the DOM, however, it behaves differently the first time appends the setAttribute correctly. The second time does not work. I'm investigating why.
Verified Brisa is working perfect on version 0.1.3.canary.4
Describe the bug When loading a web component with defined onMount, then doing SPA navigation to another page, and come back to the previous page, onMount won't get triggered again.
The bug seems because the component never gets unmounted after changing page?
To Reproduce Pending to add a reproduction @AlbertSabate (Will do this week) and potentially more information about it.
Expected behavior onMount should be triggered every time the component is mounted. Component should be properly unmounted if you navigate using SPA to a page where this component does not exists.