-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Failing to set <svelte:head>
element with getAttribute is not a function
#15337
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
Especially if it happens seemingly randomly it's very important to provide a reproduction. I know it's hard but without a reproduction we would have no way to know if something else in your setup is causing this problem. At very minimum we need a repo where you know it could happen from time time, even better if you have a clear reproduction steps. |
I've forgot to add the disclaimer from the previous issue. I know reproductions are important, I would have loved to create an MRE, but it was just impossible. This issue is more for documentation, hoping that someone else or future-self can benefit from. Will add one if viable. Thanks for the comment. You can close both as off-topic if you desire. |
If the bug is there we need to fix it...we just need a jump start to not waste hours on something that might not be an issue. |
@hyunbinseo some things that might help you narrow down the reproduction Can you
|
<!-- [ -->
<!-- seems to exist here in-between the comment and the link element -->
<link rel="icon" href="/src/lib/static/logo.svg?no-inline">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--[--><script type="text/javascript" nonce="e27035d7e842472f84c3ac211fa" src="//local.adguard.org?ts=1740104669736&type=content-script&dmn=localhost:5173&url=http%3A%2F%2Flocalhost%3A5173%2Fblank&app=firefox.exe&css=2&js=1&rel=1&rji=1&sbe=0&stealth=1&st-loc&st-dnt"></script>
<script type="text/javascript" nonce="e27035d7e842472f84c3ac211fa" src="//local.adguard.org?ts=1740104669736&name=AdGuard%20Extra&name=AdGuard%20Popup%20Blocker&type=user-script"></script><link rel="icon" href="/src/lib/static/logo.svg?no-inline"><!--]-->
</head>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--[-->
<script
type="text/javascript"
nonce="e27035d7e842472f84c3ac211fa"
src="//local.adguard.org?ts=1740104669736&type=content-script&dmn=localhost:5173&url=http%3A%2F%2Flocalhost%3A5173%2Fblank&app=firefox.exe&css=2&js=1&rel=1&rji=1&sbe=0&stealth=1&st-loc&st-dnt"
></script>
<script
type="text/javascript"
nonce="e27035d7e842472f84c3ac211fa"
src="//local.adguard.org?ts=1740104669736&name=AdGuard%20Extra&name=AdGuard%20Popup%20Blocker&type=user-script"
></script><link rel="icon" href="/src/lib/static/logo.svg?no-inline" />
<!--]-->
</head> |
It looks like AdGuard injects two scripts with |
I still don't get why this happens randomly though. I've only experienced this 3 times at 10/10, 10/15, and 2/19. I did not modifying the source code at all as mentioned above. I am curious if @bobvork is an Adguard user #15336 (comment) |
Ever since moving to Svelte 5, I have also been seeing this error appear in sentry.io for an extremely small portion of users. The stack traces point to the first line inside a I haven't been able to reproduce at all so far. I tried installing AdGuard and it didn't trigger it for me. There is nothing special about my code. It's effectively the official SvelteKit template with TS, Tailwind, and a meta tag that uses a variable, like in OP's post. |
Its looks like a race condition between svelte and plugin code. For me it's the BitWarden plugin on Firefox. It injects a script in the head section in a seemingly random location, it seems that depending on where (or when) it lands this messes up the hydration. Triggering that svelte seems to iterate over the head elements in a hardcoded order and doesnt expect this element: var n = V0();
Q(
a => {
var f = j0(),
w = h(f),
C = e(w, 2);
o(C, 'href', D0);
var q = e(C, 2);
o(q, 'href', M0);
var P = e(q, 2);
o(P, 'href', U0);
var n0 = e(P, 2);
o(n0, 'href', Z0), note: the function what i see happening in the dom before the error is that svelte injected attributes in the unexpected script tag and then tries to step to the next element and unexpectedly gets a text element causing the crash when it calls getAttribute on it. I guess the problem might be that svelte wrongly assumes the head section cannot be modified before or during running the code stepping over each element. Hope this helps.
@hyunbinseo . The position where BitWarden injects the script tag looks pretty random which could explain this.
@wildyaboku maybe worth to check if these happen to be Firefox users? To figure out if it's either an issue with the Firefox plugin system or with specific plugins regardless of browser. |
Thanks for the insights @Sasja. I checked sentry and the vast majority are Chrome (up to the latest stable versions), with Chromium-based browsers (particularly new Edge), Firefox, Opera, and even Safari mixed in, both mobile and desktop for all. So it doesn't seem to have a favorite browser in my case. 😦 |
Has anyone determined the fix or underlying issue causing this error to occur? |
Cause: some extension modifies DOM (head in this case) and the order of nodes became not the one Svelte expects. |
Nope. Running both Playwright and a Guest window right here and still experiencing the bug. |
Can you provide a repro then? |
Was going to link one here, but it doesn't seem to want to run in the sandbox. But after checking again it seems to instead be an issue linked to bits-ui rather than svelte itself. Sorry about that. |
Describe the bug
This Svelte code randomly causes the following issue:
Caution
Uncaught (in promise) TypeError: element2.getAttribute is not a function
Reproduction
Failed to create a reproduction.
It suddenly happens without changing a single-line of code in an existing, working, error free code-base.
Attempt for debugging documented in this issue:
TypeError: element2.getAttribute is not a function
#15336Logs
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: