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

hasAttribute is not a function #15241

Open
KTibow opened this issue Feb 8, 2025 · 1 comment · May be fixed by #15259
Open

hasAttribute is not a function #15241

KTibow opened this issue Feb 8, 2025 · 1 comment · May be fixed by #15259

Comments

@KTibow
Copy link

KTibow commented Feb 8, 2025

Describe the bug

some specific code specifically in sveltekit specifically when built causes a runtime error, likely due to there being no value assigned

this may seem like a silly case but it makes sense when only demonstrating UI components

if this behavior shouldn't be allowed, then svelte should error at compile time

Reproduction

https://github.com/KTibow/hasattributebug

Logs

2.C2l9EObT.js:36 Uncaught (in promise) TypeError: input.hasAttribute is not a function
    at Array.remove_defaults (2.C2l9EObT.js:36:15)
    at run_all (BjTd4EYN.js:18:11)
    at process_idle_tasks (BjTd4EYN.js:787:3)
    at flush_tasks (BjTd4EYN.js:808:5)
    at flush_sync (BjTd4EYN.js:1265:5)
    at new Svelte4Component (app.LvR6wlp0.js:446:7)
    at new <anonymous> (app.LvR6wlp0.js:395:7)
    at initialize (DSRet70y.js:1061:10)
    at _hydrate (DSRet70y.js:2210:3)
    at async Module.start (DSRet70y.js:973:5)

System Info

System:
    OS: Linux 6.12 Fedora Linux 41 (Workstation Edition)
    CPU: (8) x64 Intel(R) Core(TM) i5-1035G4 CPU @ 1.10GHz
    Memory: 7.24 GB / 15.21 GB
    Container: Yes
    Shell: 3.7.0 - /usr/bin/fish
  Binaries:
    Node: 22.12.0 - ~/.local/share/pnpm/node
    npm: 10.9.0 - ~/.local/share/pnpm/npm
    pnpm: 10.2.0 - ~/.local/share/pnpm/pnpm
  npmPackages:
    svelte: ^5.0.0 => 5.19.9

Severity

annoyance

@ranjan-purbey
Copy link

ranjan-purbey commented Feb 8, 2025

This works:

<!-- routes/+page.svelte -->
<input checked />

This fails:

<!-- routes/+page.svelte -->
text <input checked />

and so does this:

<!-- routes/+page.svelte -->
<div></div>
<input checked />

This works again:

<!-- routes/+page.svelte -->
<div></div>
<div>
    <input checked />
</div>

and so does this:

<!-- routes/+page.svelte -->
<div></div>
<input />

Issue occurs in both dev and preview. With JS disabled in the browser, the page loads fine though. Also no issue when running the same code in Svelte REPL or when using svelte template with npm create vite.
Kit versions tested: 2.17.1, 2.5.3
Svelte versions tested: 5.19.9. 5.0.0

Diff of compiler outputs in the two cases
--- just_input.js	2025-02-08 14:30:15.887715835 +0530
+++ input_with_siblings.js	2025-02-08 14:29:58.129556652 +0530
@@ -1,21 +1,23 @@
-import { createHotContext as __vite__createHotContext } from "/@vite/client";import.meta.hot = __vite__createHotContext("/src/routes/+layout.svelte");import "/node_modules/.vite/deps/svelte_internal_disclose-version.js?v=44ac6c46";
+import { createHotContext as __vite__createHotContext } from "/@vite/client";
+import "/node_modules/.vite/deps/svelte_internal_disclose-version.js?v=44ac6c46";
 import "/node_modules/.vite/deps/svelte_internal_flags_legacy.js?v=44ac6c46";
-
+import.meta.hot = __vite__createHotContext("/src/routes/+layout.svelte");
 $.mark_module_start();
 _layout[$.FILENAME] = 'src/routes/+layout.svelte';
 
 import * as $ from "/node_modules/.vite/deps/svelte_internal_client.js?v=44ac6c46";
 
-var root = $.add_locations($.template(`<input checked>`), _layout[$.FILENAME], [[4, 0]]);
+var root = $.add_locations($.template(`<input checked> .`, 1), _layout[$.FILENAME], [[4, 0]]);
 
 function _layout($$anchor, $$props) {
 	$.check_target(new.target);
 	$.push($$props, false, _layout);
 
-	var input = root();
+	var fragment = root();
 
-	$.remove_input_defaults(input);
-	$.append($$anchor, input);
+	$.remove_input_defaults();
+	$.next();
+	$.append($$anchor, fragment);
 	return $.pop({ ...$.legacy_api() });
 }

Here we can see that remove_input_defaults is called without any args in the case where root-level <input> has a sibling node.

ranjan-purbey added a commit to ranjan-purbey/svelte that referenced this issue Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants