-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Improved support for
imageSrcSet
+ imageSizes
in route `link…
…s` (#184) (#2944) Improves support for returned links that include an `imagesrcset` attribute to preload images when matched against a responsive set of URLs. This only works when `rel === 'preload'` and `as === 'image'`. https://html.spec.whatwg.org/commit-snapshots/cb4f5ff75de5f4cbd7013c4abad02f21c77d4d1c/#attr-link-imagesrcset Prior to this change, a few problems with our implementation: 1. Our types for `HtmlLinkDescriptor` make `href` required. This is true _unless_ a link includes `imagesrcset` and `imagesizes`, though `imagesrcset` and `href` will also work with or without `imagesizes` according to the spec. This change uses an intersection type to account for these cases. 2. React 17 was released prior to these attributes being accepted into the spec and implemented by browsers, so passing the props as camel-cased will issue a warning about unsupported DOM props. Our types recognized this and supported the all-lowercase version to skip the warning and forward the attribute to the node, but React 18 now recognizes the camel-cased version. This change updates our types to use the camel-cased prop names, but it will support either at runtime and normalize the object based on the detected version of React. 3. Because we use `href` + `rel` as a key, links without an `href` will have duplicate keys. So `imageSrcSet` is added as a fallback to prevent that.
- Loading branch information
Showing
4 changed files
with
275 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.