-
-
Notifications
You must be signed in to change notification settings - Fork 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
adapter-static: Placing media before srcset in a <source> tag will prevent srcset from being crawled #2742
Comments
The way the regex is written in
srcset attribute is first. I don't have time to build a better regex right now, but that's definitely the cause of this behavior.
|
I've wondered whether it would be a good idea to give up on regexes here and just use something like parse5 to parse the HTML and walk the AST ourselves to find stuff more robustly. If this only ever happens at build time, I guess I see less of a cost to doing this with a bigger slower library. |
Considering projects such as Elderjs, Nextjs (with hybrid mode), etc, and considering the (implied?) objective of making Kit a write-once, deploy however framework, I would call back to one of Rich's arguments about the perils of "convenient escape hatches". I've got a fair bit of regex deep-dive in me. Per the discord discussions about compositional regex, lookaround assertions, etc, I'd like to take a swing at a full refactor of the regex in prerender.js to address all related issues (there seem to be many). Would it be possible to get a clearer definition of the objectives by aggregating the related issues somehow? It may also help to review/merge from PRs any valid tests related to regex in this file. Would help me during the refactoring process to validate as I go. Of course, maintainability will remain a top concern - but I don't think it has to be sacrificed here in favor of a dependency-free solution. I can open a new issue for all prerender.js regex, if you want to link it all under that? Lmk. |
@Conduitry I prefer to use parse5 way instead of the regexes. |
I think I'm in favor of a proper parser instead of regexes, too. Two recent Svelte bug reports —sveltejs/svelte#6844 and sveltejs/svelte#6923 — were both caused (I'm 95% certain) by an imprecision in the regexes Svelte uses to detect opening & closing |
fixed by #3288 |
Describe the bug
If the attributes in a
<source>
tag appear like so<source media="(max-width: 400px)" srcset="/myimage.jpg">
the srcset won't be crawled and the image won't be downloaded.When arranged like this
<source srcset="/myimage.jpg" media="(max-width: 400px)">
it works as expected.Reproduction
Add a
<source>
tag as mentioned above and run a SvelteKit build with adapter-static configured. Images will not be downloaded as expected.Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: