Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: support older browsers in docker template (#5346)

Bogdan Chadkin0f13788fdb73
diff --git a/fixtures/react-router-docker/app/constants.mjs b/fixtures/react-router-docker/app/constants.mjs
index 5dbbec107c..dedee9f093 100644
--- a/fixtures/react-router-docker/app/constants.mjs
+++ b/fixtures/react-router-docker/app/constants.mjs
@@ -4,6 +4,19 @@
*/
export const assetBaseUrl = "/assets/";
+/**
+ * URL.canParse(props.src)
+ * @type {(url: string) => boolean}
+ */
+const UrlCanParse = (url) => {
+ try {
+ new URL(url);
+ return true;
+ } catch {
+ return false;
+ }
+};
+
/**
* @type {import("@webstudio-is/image").ImageLoader}
*/
@@ -12,7 +25,7 @@ export const imageLoader = (props) => {
return props.src;
}
// handle absolute urls
- const path = URL.canParse(props.src) ? `/${props.src}` : props.src;
+ const path = UrlCanParse(props.src) ? `/${props.src}` : props.src;
// https://github.com/unjs/ipx?tab=readme-ov-file#modifiers
return `/_image/w_${props.width},q_${props.quality}${path}`;
};
diff --git a/packages/cli/templates/react-router-docker/app/constants.mjs b/packages/cli/templates/react-router-docker/app/constants.mjs
index 5dbbec107c..dedee9f093 100644
--- a/packages/cli/templates/react-router-docker/app/constants.mjs
+++ b/packages/cli/templates/react-router-docker/app/constants.mjs
@@ -4,6 +4,19 @@
*/
export const assetBaseUrl = "/assets/";
+/**
+ * URL.canParse(props.src)
+ * @type {(url: string) => boolean}
+ */
+const UrlCanParse = (url) => {
+ try {
+ new URL(url);
+ return true;
+ } catch {
+ return false;
+ }
+};
+
/**
* @type {import("@webstudio-is/image").ImageLoader}
*/
@@ -12,7 +25,7 @@ export const imageLoader = (props) => {
return props.src;
}
// handle absolute urls
- const path = URL.canParse(props.src) ? `/${props.src}` : props.src;
+ const path = UrlCanParse(props.src) ? `/${props.src}` : props.src;
// https://github.com/unjs/ipx?tab=readme-ov-file#modifiers
return `/_image/w_${props.width},q_${props.quality}${path}`;
};