Skip to content

Commit 0f13788

Browse files
authored
fix: support older browsers in docker template (#5346)
URL.canParse is very new method and need to be polyfilled. Docker is the only place it is used.
1 parent fc03300 commit 0f13788

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

fixtures/react-router-docker/app/constants.mjs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
*/
55
export const assetBaseUrl = "/assets/";
66

7+
/**
8+
* URL.canParse(props.src)
9+
* @type {(url: string) => boolean}
10+
*/
11+
const UrlCanParse = (url) => {
12+
try {
13+
new URL(url);
14+
return true;
15+
} catch {
16+
return false;
17+
}
18+
};
19+
720
/**
821
* @type {import("@webstudio-is/image").ImageLoader}
922
*/
@@ -12,7 +25,7 @@ export const imageLoader = (props) => {
1225
return props.src;
1326
}
1427
// handle absolute urls
15-
const path = URL.canParse(props.src) ? `/${props.src}` : props.src;
28+
const path = UrlCanParse(props.src) ? `/${props.src}` : props.src;
1629
// https://github.com/unjs/ipx?tab=readme-ov-file#modifiers
1730
return `/_image/w_${props.width},q_${props.quality}${path}`;
1831
};

packages/cli/templates/react-router-docker/app/constants.mjs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
*/
55
export const assetBaseUrl = "/assets/";
66

7+
/**
8+
* URL.canParse(props.src)
9+
* @type {(url: string) => boolean}
10+
*/
11+
const UrlCanParse = (url) => {
12+
try {
13+
new URL(url);
14+
return true;
15+
} catch {
16+
return false;
17+
}
18+
};
19+
720
/**
821
* @type {import("@webstudio-is/image").ImageLoader}
922
*/
@@ -12,7 +25,7 @@ export const imageLoader = (props) => {
1225
return props.src;
1326
}
1427
// handle absolute urls
15-
const path = URL.canParse(props.src) ? `/${props.src}` : props.src;
28+
const path = UrlCanParse(props.src) ? `/${props.src}` : props.src;
1629
// https://github.com/unjs/ipx?tab=readme-ov-file#modifiers
1730
return `/_image/w_${props.width},q_${props.quality}${path}`;
1831
};

0 commit comments

Comments
 (0)