Skip to content

Commit 3a913f4

Browse files
committed
feat!: remove deprecated properties from HtmlLinkDescriptor, LinkDescriptor & PrefetchPageDescriptor types
1 parent 3212276 commit 3a913f4

File tree

7 files changed

+40
-97
lines changed

7 files changed

+40
-97
lines changed

.changeset/large-goats-double.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@remix-run/react": major
3+
"@remix-run/server-runtime": major
4+
---
5+
6+
Remove `imagesizes` & `imagesrcset` properties from `HtmlLinkDescriptor`, `LinkDescriptor` & `PrefetchPageDescriptor` types

integration/action-test.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ test.describe("actions", () => {
110110

111111
test.beforeEach(({ page }) => {
112112
page.on("console", (msg) => {
113-
let text = msg.text();
114-
if (!/DEPRECATED.*imagesizes.*imagesrcset/.test(text)) {
115-
logs.push(text);
116-
}
113+
logs.push(msg.text());
117114
});
118115
});
119116

integration/defer-test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1330,8 +1330,7 @@ function monitorConsole(page: Page) {
13301330
let arg0 = await args[0].jsonValue();
13311331
if (
13321332
typeof arg0 === "string" &&
1333-
(arg0.includes("Download the React DevTools") ||
1334-
/DEPRECATED.*imagesizes.*imagesrcset/.test(arg0))
1333+
arg0.includes("Download the React DevTools")
13351334
) {
13361335
continue;
13371336
}

packages/remix-react/components.tsx

+15-33
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import type {
5252
V2_MetaMatch,
5353
V2_MetaMatches,
5454
} from "./routeModules";
55-
import { logDeprecationOnce } from "./warnings";
5655

5756
function useDataRouterContext() {
5857
let context = React.useContext(DataRouterContext);
@@ -314,12 +313,6 @@ export function composeEventHandlers<
314313
};
315314
}
316315

317-
let linksWarning =
318-
"⚠️ REMIX FUTURE CHANGE: The behavior of links `imagesizes` and `imagesrcset` will be changing in v2. " +
319-
"Only the React camel case versions will be valid. Please change to `imageSizes` and `imageSrcSet`. " +
320-
"For instructions on making this change see " +
321-
"https://remix.run/docs/en/v1.15.0/pages/v2#links-imagesizes-and-imagesrcset";
322-
323316
/**
324317
* Renders the `<link>` tags for the current routes.
325318
*
@@ -341,12 +334,6 @@ export function Links() {
341334
[matches, routeModules, manifest]
342335
);
343336

344-
React.useEffect(() => {
345-
if (links.some((link) => "imagesizes" in link || "imagesrcset" in link)) {
346-
logDeprecationOnce(linksWarning);
347-
}
348-
}, [links]);
349-
350337
return (
351338
<>
352339
{links.map((link) => {
@@ -355,37 +342,32 @@ export function Links() {
355342
}
356343

357344
let imageSrcSet: string | null = null;
345+
let imageSizes: string | null = null;
358346

359347
// In React 17, <link imageSrcSet> and <link imageSizes> will warn
360348
// because the DOM attributes aren't recognized, so users need to pass
361349
// them in all lowercase to forward the attributes to the node without a
362350
// warning. Normalize so that either property can be used in Remix.
363-
if ("useId" in React) {
364-
if (link.imagesrcset) {
365-
link.imageSrcSet = imageSrcSet = link.imagesrcset;
366-
delete link.imagesrcset;
367-
}
368-
369-
if (link.imagesizes) {
370-
link.imageSizes = link.imagesizes;
371-
delete link.imagesizes;
372-
}
373-
} else {
374-
if (link.imageSrcSet) {
375-
link.imagesrcset = imageSrcSet = link.imageSrcSet;
376-
delete link.imageSrcSet;
377-
}
351+
let imageSizesKey = "useId" in React ? "imageSizes" : "imagesizes";
352+
let imageSrcSetKey = "useId" in React ? "imageSrcSet" : "imagesrcset";
353+
if (link.imageSrcSet) {
354+
imageSrcSet = link.imageSrcSet;
355+
delete link.imageSrcSet;
356+
}
378357

379-
if (link.imageSizes) {
380-
link.imagesizes = link.imageSizes;
381-
delete link.imageSizes;
382-
}
358+
if (link.imageSizes) {
359+
imageSizes = link.imageSizes;
360+
delete link.imageSizes;
383361
}
384362

385363
return (
386364
<link
387365
key={link.rel + (link.href || "") + (imageSrcSet || "")}
388-
{...link}
366+
{...{
367+
...link,
368+
[imageSizesKey]: imageSizes,
369+
[imageSrcSetKey]: imageSrcSet,
370+
}}
389371
/>
390372
);
391373
})}

packages/remix-react/links.ts

+12-28
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,10 @@ interface HtmlLinkPreloadImage extends HtmlLinkProps {
173173
export type HtmlLinkDescriptor =
174174
// Must have an href *unless* it's a `<link rel="preload" as="image">` with an
175175
// `imageSrcSet` and `imageSizes` props
176-
(
177-
| (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">)
178-
| (HtmlLinkPreloadImage &
179-
Pick<Required<HtmlLinkPreloadImage>, "imageSizes">)
180-
| (HtmlLinkPreloadImage &
181-
Pick<Required<HtmlLinkPreloadImage>, "href"> & { imageSizes?: never })
182-
) & {
183-
/**
184-
* @deprecated Use `imageSrcSet` instead.
185-
*/
186-
imagesrcset?: string;
187-
188-
/**
189-
* @deprecated Use `imageSizes` instead.
190-
*/
191-
imagesizes?: string;
192-
};
176+
| (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">)
177+
| (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "imageSizes">)
178+
| (HtmlLinkPreloadImage &
179+
Pick<Required<HtmlLinkPreloadImage>, "href"> & { imageSizes?: never });
193180

194181
export interface PrefetchPageDescriptor
195182
extends Omit<
@@ -200,8 +187,6 @@ export interface PrefetchPageDescriptor
200187
| "sizes"
201188
| "imageSrcSet"
202189
| "imageSizes"
203-
| "imagesrcset"
204-
| "imagesizes"
205190
| "as"
206191
| "color"
207192
| "title"
@@ -302,23 +287,22 @@ export function isPageLinkDescriptor(
302287
return object != null && typeof object.page === "string";
303288
}
304289

305-
export function isHtmlLinkDescriptor(
306-
object: any
307-
): object is HtmlLinkDescriptor {
308-
if (object == null) return false;
290+
function isHtmlLinkDescriptor(object: any): object is HtmlLinkDescriptor {
291+
if (object == null) {
292+
return false;
293+
}
309294

310-
// <link> may not have an href if <link rel="preload"> is used with imagesrcset + imagesizes
295+
// <link> may not have an href if <link rel="preload"> is used with imageSrcSet + imageSizes
311296
// https://github.com/remix-run/remix/issues/184
312297
// https://html.spec.whatwg.org/commit-snapshots/cb4f5ff75de5f4cbd7013c4abad02f21c77d4d1c/#attr-link-imagesrcset
313298
if (object.href == null) {
314299
return (
315300
object.rel === "preload" &&
316-
(typeof object.imageSrcSet === "string" ||
317-
typeof object.imagesrcset === "string") &&
318-
(typeof object.imageSizes === "string" ||
319-
typeof object.imagesizes === "string")
301+
typeof object.imageSrcSet === "string" &&
302+
typeof object.imageSizes === "string"
320303
);
321304
}
305+
322306
return typeof object.rel === "string" && typeof object.href === "string";
323307
}
324308

packages/remix-react/warnings.ts

-10
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,3 @@ export function warnOnce(condition: boolean, message: string): void {
66
console.warn(message);
77
}
88
}
9-
10-
export function logDeprecationOnce(
11-
message: string,
12-
key: string = message
13-
): void {
14-
if (process.env.NODE_ENV !== "production" && !alreadyWarned[key]) {
15-
alreadyWarned[key] = true;
16-
console.warn(message);
17-
}
18-
}

packages/remix-server-runtime/links.ts

+5-20
Original file line numberDiff line numberDiff line change
@@ -163,25 +163,12 @@ interface HtmlLinkPreloadImage extends HtmlLinkProps {
163163
* WHATWG Specification: https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
164164
*/
165165
export type HtmlLinkDescriptor =
166-
// Must have an href *unless* it's a `<link rel="preload" as="image">` with an
166+
// Must have a href *unless* it's a `<link rel="preload" as="image">` with an
167167
// `imageSrcSet` and `imageSizes` props
168-
(
169-
| (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">)
170-
| (HtmlLinkPreloadImage &
171-
Pick<Required<HtmlLinkPreloadImage>, "imageSizes">)
172-
| (HtmlLinkPreloadImage &
173-
Pick<Required<HtmlLinkPreloadImage>, "href"> & { imageSizes?: never })
174-
) & {
175-
/**
176-
* @deprecated Use `imageSrcSet` instead.
177-
*/
178-
imagesrcset?: string;
179-
180-
/**
181-
* @deprecated Use `imageSizes` instead.
182-
*/
183-
imagesizes?: string;
184-
};
168+
| (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">)
169+
| (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "imageSizes">)
170+
| (HtmlLinkPreloadImage &
171+
Pick<Required<HtmlLinkPreloadImage>, "href"> & { imageSizes?: never });
185172

186173
export interface PageLinkDescriptor
187174
extends Omit<
@@ -192,8 +179,6 @@ export interface PageLinkDescriptor
192179
| "sizes"
193180
| "imageSrcSet"
194181
| "imageSizes"
195-
| "imagesrcset"
196-
| "imagesizes"
197182
| "as"
198183
| "color"
199184
| "title"

0 commit comments

Comments
 (0)