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

Add missing fetchpriority property to img on html element #8099

Closed
harrytran998 opened this issue Dec 9, 2022 · 10 comments · Fixed by #10388
Closed

Add missing fetchpriority property to img on html element #8099

harrytran998 opened this issue Dec 9, 2022 · 10 comments · Fixed by #10388

Comments

@harrytran998
Copy link

Describe the problem

Here the bug:

Object literal may only specify known properties, and 'fetchpriority' does not exist in type 'HTMLProps<"img", HTMLAttributes<any>>'.

Describe the proposed solution

Just add the missing peace? 😆

Alternatives considered

I actually don't have enough knowledge to think of an alternative solution 🥹. Hope anyone can help.

Importance

would make my life easier

@baseballyama
Copy link
Member

You need to provide a REPL.

And GitHub issues aren't the right place for support questions like this. Please ask on StackOverflow or in our Discord chat room.

@bdougherty
Copy link
Contributor

bdougherty commented Jan 12, 2023

@baseballyama this isn't really a support question in that way.

fetchpriority is a new attribute on <img> and <link> that should be recognized by Svelte. It is missing from the declaration here:

export interface HTMLImgAttributes extends HTMLAttributes<HTMLImageElement> {

fetchpriority?: 'high' | 'low' | 'auto' | undefined | null;

I don't really know how to do a REPL for this because the svelte.dev/repl does not report any issue, but svelte-check does. Here is the svelte-check error from my SvelteKit project:

Error: Argument of type '{ src: string; srcset: string; alt: string; loading: "lazy" | undefined; fetchpriority: string | undefined; }' is not assignable to parameter of type 'HTMLProps<"img", HTMLAttributes<any>>'.
  Object literal may only specify known properties, and '"fetchpriority"' does not exist in type 'HTMLProps<"img", HTMLAttributes<any>>'. (ts)
                                        loading={priority ? undefined : 'lazy'}
                                        fetchpriority={priority ? 'high' : undefined}
                                />

All you need to do is add <img src="https://svelte.dev/_app/immutable/assets/stopwar-947a4798.svg" alt="Svelte" fetchpriority="high" /> somewhere.

@jamesarosen
Copy link

@bdougherty is correct. This isn't a "tech support" issue. fetchpriority is still experimental, but it does have pretty good browser support. I would expect to be able to use it in a Svelte app.

References:

The excellent @KTibow put together a replication here.

@jamesarosen
Copy link

The Svelte docs have a section on Enhancing built-in DOM types. Based off that section, I would expect this workaround to work, but it does not:

declare namespace svelteHTML {
	interface HTMLImgAttributes {
		fetchpriority: "auto" | "low" | "high" | null | undefined
	}
}

@baseballyama baseballyama reopened this Jul 16, 2023
@baseballyama baseballyama added the good first issue A small, encapsulated issue, ideal for a new contributor to Svelte to tackle. label Jul 16, 2023
@jasonlyu123
Copy link
Member

Only chromium support it in the stable release. I don't think it is "have pretty good browser support". Typescript also doesn't have it in their DOM definition. We have an issue with it in the language tools repo. But I declined it because only chromium support it. Although it has been nearly a year since then, The situation is basically the same.

@KTibow
Copy link

KTibow commented Jul 16, 2023

Around 67% of traffic can use it already, so it would still be useful in the cases where it works. Safari has it behind a flag too. On the other hand, this issue might be resolved by having better documentation on how to extend element types, as it seems most people fail while doing so.

@jamesarosen
Copy link

On the other hand, this issue might be resolved by having better documentation on how to extend element types

Agreed. fetchpriority is only one experimental attribute. There are many others and there will be more over the years.

https://www.sveltelab.dev/x81qkcafntbqgd5 shows that the documented method for extending built-in types does not work. (Or that the documentation is insufficiently clear for how to add attributes to one element type.)

@jasonlyu123
Copy link
Member

jasonlyu123 commented Jul 17, 2023

Based off that section, I would expect this workaround to work, but it does not:

Make sure you're putting the declaration in .d.ts that is not a module, i.e. has no import/export. If it's a module, you must wrap it inside a global block like the App namespace in the SvelteKit's app.d.ts. Otherwise, TypeScript will ignore those.

@Zachiah
Copy link
Contributor

Zachiah commented Jul 25, 2023

Is this something that you guys want getting fixed? People in the discord are asking for first tasks so I was looking for issues with the "good first issue" tag and I found this, but based on the conversation it sounds like you want to wait so I'm unsure about recommending they work on it.

@baseballyama baseballyama removed the good first issue A small, encapsulated issue, ideal for a new contributor to Svelte to tackle. label Jul 25, 2023
@colinhowells
Copy link

TS has absolved me of my crimes against it by my use of an ambient.d.ts file (as Svelte recommends for random NPM packages etc):

//src/ambient.d.ts

declare module '@some/npm-package-you-are-using';
declare module '*.gql'; // if you like standalone GraphQL files, just a tip

declare namespace svelteHTML {
	interface HTMLAttributes<T> {
		fetchpriority?: 'auto' | 'low' | 'high';
	}
}

dummdidumm added a commit that referenced this issue Feb 5, 2024
Fixes #8099

---------

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
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.

8 participants