-
-
Notifications
You must be signed in to change notification settings - Fork 2k
sveltekit:prefetch
seems to be invalid HTML
#3186
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
sveltekit:prefetch
seems to me invalid HTMLsveltekit:prefetch
seems to be invalid HTML
Quite interested in this - is the site public so I can test it myself :p @moritzebeling |
I think it is not inherent to my specific site. You can try it out here https://validator.w3.org/nu/#textarea and put in the following code <!DOCTYPE html>
<html lang="en">
<head>
<title>SvelteKit check if sveltekit:prefetch is valid HTML</title>
</head>
<body>
<h1>SvelteKit check if sveltekit:prefetch is valid HTML</h1>
<a href="/page" sveltekit:prefetch>Link</a>
</body>
</html> |
I think we would need to do something like |
Could |
I did some investigation on this. This change will likely need to be solved similarly for Could this perhaps be solved without a breaking change? What if we transform all It would be nice to keep the DX of To implement this, we would need to:
Suggested changelog entry:
I'd be happy to make a contribution to solve this, but have some questions... 😄
|
Since this is a low prio issue I don't expect much support, but I'm documenting my progress here anyway 🙂 Update: There are likely much better ways of solving this, but I've hacked together a partial solution here: Greenheart@545286d Status:
Let me know if there's a way to solve this with ASTs when parsing the svelte code, since that would make the solution much cleaner. However, I'm afraid that the ability to use ASTs would happen outside of SvelteKit and instead in the |
Maybe a sveltekit svelte preprocessor (maybe there already is one?) that is applied in the background could help us with most of these issues? |
That's a good idea! It actually looks like Here's the relevant code: https://github.com/sveltejs/svelte-preprocess/blob/main/src/transformers/replace.ts This means we might be able to add a default transform to the |
Using Now, we need to extend the user's |
As mentioned on the PR, I'm opposed to a transform step that changes Which means that if we were to make this change, it would be a breaking change — we would no longer be able to use If we make such a change, it should be for a good reason, not a speculative one like 'search engines might downrank you' or 'a11y tools might complain'. I'm unaware of any such impacts (and I'd expect more people to have found their way to this thread if there were), so my inclination would be to leave things as they are, but I'd be interested to hear from anyone if there's a compelling reason to switch? |
Just a noobie question - why do you need to emit the This raises the following question for a clear API - why not to export a <script>
import { prefetch } from '$app/actions';
</script>
<a use:prefetch href='/about'>About</a> |
No, it does not transform into an action, it is needed on the element. kit/packages/kit/src/runtime/client/client.js Line 1151 in d0b30f4
If we did this, it would not be possible to use it with html strings. <script>
const html = '<p><a sveltekit:prefetch href="/">Goto /</a></p>';
</script>
{@html html} |
Describe the problem
Hey, I just validated my SvelteKit website with https://validator.w3.org/nu/ and it heavily complained about
sveltekit:prefetch
not being valid HTML.Is this a problem? Maybe if some service wanted to rank the quality of some website, they would use an HTML validator and adjust the ranking accordingly?
Describe the proposed solution
To avoid that, maybe the Svelte compiler could automatically turn such things into a valid HTML attribute like
data-sveltekit="prefetch"
from where the router can pick it up?In my imagination this should be fairly easy to implement and would result in valid HTML.
Alternatives considered
No response
Importance
nice to have
Additional Information
Thank you very much for building Svelte!
The text was updated successfully, but these errors were encountered: