-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Dimension bindings intermittently add inline style="position:relative;" in Firefox #4776
Comments
It's so the injected |
Labeling this as |
Fine. Label it however you see fit, but please note that:
This makes me suspect a bug rather than an expected gotcha, but you guys are the experts. |
This also happens in the latest Edge version built on Chromium. The |
Okay so... What I have done as a workaround is that I have bound both, the <div
class="w-full h-full overflow-scroll"
bind:clientHeight={containerClientHeight}
bind:this={container}
> And then I have used onMount(async () => {
await tick();
containerClientHeight = container.clientHeight;
}) Now the |
I have been chasing down an intermittent problem on Safari where a sticky header was rendering incorrectly. I found that the problem was caused by "element.style {position: relative;}" on the element that was supposed to be sticky. I could not see anything in our code that could be causing this. Finally, I looked at bundle.js and found it coming from svelte's generated code. A quick search then brought me to this issue thread. And, yes, the element in question is using the dimension binding feature (for offsetHeight). To fix the problem I added an onMount handler for the parent component that just does element.style.position="" to clear out whatever svelte might have put there. Now the element properly behaves using the position: sticky property set in css. This seems to me to be a real bug. Imo, svelte should never be setting the position property of one of my elements under the covers. But if it's going to do that then it should at least do it in a predictable, consistent and well documented way. |
+1 |
@isaacHagoel The alternative is to use const ro = new ResizeObserver((entries) => {
for (const entry of entries) {
entry.target.dispatchEvent(new CustomEvent("elResize"));
}
});
export function resize(node: HTMLElement) {
ro.observe(node);
return {
destroy() {
ro.unobserve(node);
},
};
} <div use:resize on:elResize={(e) => foo = e.target.offsetWidth} /> |
@bluwy great idea! thanks |
FWIW, I've created a package to automatically use |
@bluwy you were able to preserve the |
@isaacHagoel anything is possible with preprocessors 😉 (PS: I'll opt-out of this conversation for a bit since it's a bit off topic, feel free to open a discussion in the repo though) |
I ran into this issue today while building a <header bind:clientHeight={header}>...</header> I was super confused why my classes weren't applying and thought I had a bug somewhere..but I eventually opened up dev tools to find the inline ghost style <style>
.absolute { position: absolute; }
.fixed { position: fixed; }
</style> Would be cool to see a fix for this in the future! |
Agree that |
FWIW, this also happens to me intermittently on Chrome. Can't reproduce 100% reliably, but |
This is still an issue. Took me an entire day to figure out why a list of components I was creating was getting |
I've faced this issue in Vivaldi (chromium) browser, it appears 100% times. |
Svelte 5 uses a resize observer instead, which should solve this |
Using dimension bindings on an element will sometimes add an inline style
position:relative;
in Firefox. This overrides any other CSS positioning that may be defined on the element. The problem doesn't happen in Chrome.The code below (borrowed from w3schools.com) reproduces the problem on my system roughly 50% of the time (although you may have to reload 10-20 times to see it, maybe due to page caching). I'm using Svelte 3.22.1 with Rollup, Firefox 75, Windows 10.
The inner div should be positioned to the right side of the outer div. When Svelte sometimes gives it
position:relative;
it is positioned to the left.EDIT: I can't reproduce this problem in Svelte's REPL. This is another sign (along with the intermittency) that makes me think the bug is lifecycle related. If so then maybe the page loading delays caused by the REPL infrastructure avoid the problem.
The text was updated successfully, but these errors were encountered: