Skip to content

Commit

Permalink
refactor: drop image base url from cli and templates
Browse files Browse the repository at this point in the history
In all cli templates asset base url and image base url are the same
so we can safely switch.

Removed image loader from prebuild.ts.

Dropped imageBaseUrl from sdk react context.
  • Loading branch information
TrySound committed Dec 11, 2024
1 parent f7f98b6 commit c1045ce
Show file tree
Hide file tree
Showing 51 changed files with 98 additions and 183 deletions.
1 change: 0 additions & 1 deletion apps/builder/app/canvas/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ const useElementsTree = (
<ReactSdkContext.Provider
value={{
renderer: isPreviewMode ? "preview" : "canvas",
imageBaseUrl: "/cgi/image/",
assetBaseUrl: params.assetBaseUrl,
imageLoader,
resources: {},
Expand Down
1 change: 0 additions & 1 deletion apps/builder/app/routes/_canvas.canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
}

const params: Params = {
imageBaseUrl: "/cgi/image/",
assetBaseUrl: env.ASSET_BASE_URL,
};

Expand Down
2 changes: 0 additions & 2 deletions apps/builder/app/shared/nano-states/props.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ test("resolve asset prop values when params is provided", () => {

$params.set({
assetBaseUrl: "/asset/",
imageBaseUrl: "/image/",
});
expect(
$propValuesByInstanceSelector.get().get(JSON.stringify(["box"]))
Expand Down Expand Up @@ -279,7 +278,6 @@ test("resolve page prop values when params is provided", () => {

$params.set({
assetBaseUrl: "/asset/",
imageBaseUrl: "/image/",
});
expect(
$propValuesByInstanceSelector.get().get(JSON.stringify(["box"]))
Expand Down
6 changes: 3 additions & 3 deletions fixtures/ssg-netlify-by-project-id/app/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ export const imageLoader = (props) => {
}

if (process.env.NODE_ENV !== "production") {
return imageBaseUrl + props.src;
return assetBaseUrl + props.src;
}

if (props.format === "raw") {
return imageBaseUrl + props.src;
return assetBaseUrl + props.src;
}

// https://docs.netlify.com/image-cdn/overview/
return (
"/.netlify/images?url=" +
encodeURIComponent(imageBaseUrl + props.src) +
encodeURIComponent(assetBaseUrl + props.src) +
"&w=" +
props.width +
"&q=" +
Expand Down
7 changes: 1 addition & 6 deletions fixtures/ssg-netlify-by-project-id/pages/index/+Page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { PageContext } from "vike/types";
import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime";
import {
assetBaseUrl,
imageBaseUrl,
imageLoader,
} from "../../app/constants.mjs";
import { assetBaseUrl, imageLoader } from "../../app/constants.mjs";
import { Page } from "../../app/__generated__/_index";

const PageComponent = ({ data }: { data: PageContext["data"] }) => {
Expand All @@ -14,7 +10,6 @@ const PageComponent = ({ data }: { data: PageContext["data"] }) => {
value={{
imageLoader,
assetBaseUrl,
imageBaseUrl,
resources,
}}
>
Expand Down
2 changes: 1 addition & 1 deletion fixtures/ssg/app/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export const imageLoader = ({ src }) => {
return src;
}

return imageBaseUrl + src;
return assetBaseUrl + src;
};
7 changes: 1 addition & 6 deletions fixtures/ssg/pages/another-page/+Page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { PageContext } from "vike/types";
import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime";
import {
assetBaseUrl,
imageBaseUrl,
imageLoader,
} from "../../app/constants.mjs";
import { assetBaseUrl, imageLoader } from "../../app/constants.mjs";
import { Page } from "../../app/__generated__/[another-page]._index";

const PageComponent = ({ data }: { data: PageContext["data"] }) => {
Expand All @@ -14,7 +10,6 @@ const PageComponent = ({ data }: { data: PageContext["data"] }) => {
value={{
imageLoader,
assetBaseUrl,
imageBaseUrl,
resources,
}}
>
Expand Down
7 changes: 1 addition & 6 deletions fixtures/ssg/pages/index/+Page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { PageContext } from "vike/types";
import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime";
import {
assetBaseUrl,
imageBaseUrl,
imageLoader,
} from "../../app/constants.mjs";
import { assetBaseUrl, imageLoader } from "../../app/constants.mjs";
import { Page } from "../../app/__generated__/_index";

const PageComponent = ({ data }: { data: PageContext["data"] }) => {
Expand All @@ -14,7 +10,6 @@ const PageComponent = ({ data }: { data: PageContext["data"] }) => {
value={{
imageLoader,
assetBaseUrl,
imageBaseUrl,
resources,
}}
>
Expand Down
2 changes: 1 addition & 1 deletion fixtures/webstudio-cloudflare-template/app/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const imageBaseUrl = "/assets/";
* @type {import("@webstudio-is/image").ImageLoader}
*/
export const imageLoader = ({ src }) => {
return imageBaseUrl + src;
return assetBaseUrl + src;
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
projectId,
contactEmail,
} from "../__generated__/[another-page]._index.server";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";
import { assetBaseUrl, imageLoader } from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";

Expand Down Expand Up @@ -329,7 +329,6 @@ const Outlet = () => {
value={{
imageLoader,
assetBaseUrl,
imageBaseUrl,
resources,
}}
>
Expand Down
3 changes: 1 addition & 2 deletions fixtures/webstudio-cloudflare-template/app/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
projectId,
contactEmail,
} from "../__generated__/_index.server";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";
import { assetBaseUrl, imageLoader } from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";

Expand Down Expand Up @@ -329,7 +329,6 @@ const Outlet = () => {
value={{
imageLoader,
assetBaseUrl,
imageBaseUrl,
resources,
}}
>
Expand Down
2 changes: 1 addition & 1 deletion fixtures/webstudio-custom-template/app/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const imageBaseUrl = "/custom-folder/";
* @type {import("@webstudio-is/image").ImageLoader}
*/
export const imageLoader = ({ src }) => {
return imageBaseUrl + src;
return assetBaseUrl + src;
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
projectId,
contactEmail,
} from "../__generated__/[script-test]._index.server";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";
import { assetBaseUrl, imageLoader } from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";

Expand Down Expand Up @@ -329,7 +329,6 @@ const Outlet = () => {
value={{
imageLoader,
assetBaseUrl,
imageBaseUrl,
resources,
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getRemixParams,
getResources,
} from "../__generated__/[sitemap.xml]._index.server";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";
import { assetBaseUrl, imageLoader } from "../constants.mjs";
import { sitemap } from "../__generated__/$resources.sitemap.xml";

const customFetch: typeof fetch = (input, init) => {
Expand Down Expand Up @@ -65,7 +65,6 @@ export const loader = async (arg: LoaderFunctionArgs) => {
value={{
imageLoader,
assetBaseUrl,
imageBaseUrl,
resources,
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
projectId,
contactEmail,
} from "../__generated__/[world]._index.server";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";
import { assetBaseUrl, imageLoader } from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";

Expand Down Expand Up @@ -329,7 +329,6 @@ const Outlet = () => {
value={{
imageLoader,
assetBaseUrl,
imageBaseUrl,
resources,
}}
>
Expand Down
3 changes: 1 addition & 2 deletions fixtures/webstudio-custom-template/app/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
projectId,
contactEmail,
} from "../__generated__/_index.server";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";
import { assetBaseUrl, imageLoader } from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";

Expand Down Expand Up @@ -329,7 +329,6 @@ const Outlet = () => {
value={{
imageLoader,
assetBaseUrl,
imageBaseUrl,
resources,
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const imageBaseUrl = "/custom-folder/";
* @type {import("@webstudio-is/image").ImageLoader}
*/
export const imageLoader = ({ src }) => {
return imageBaseUrl + src;
return assetBaseUrl + src;
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ export const imageBaseUrl = "/assets/";
*/
export const imageLoader = (props) => {
if (process.env.NODE_ENV !== "production") {
return imageBaseUrl + props.src;
return assetBaseUrl + props.src;
}

if (props.format === "raw") {
return imageBaseUrl + props.src;
return assetBaseUrl + props.src;
}

// https://docs.netlify.com/image-cdn/overview/
return (
"/.netlify/images?url=" +
encodeURIComponent(imageBaseUrl + props.src) +
encodeURIComponent(assetBaseUrl + props.src) +
"&w=" +
props.width +
"&q=" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
projectId,
contactEmail,
} from "../__generated__/[another-page]._index.server";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";
import { assetBaseUrl, imageLoader } from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";

Expand Down Expand Up @@ -329,7 +329,6 @@ const Outlet = () => {
value={{
imageLoader,
assetBaseUrl,
imageBaseUrl,
resources,
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
projectId,
contactEmail,
} from "../__generated__/_index.server";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";
import { assetBaseUrl, imageLoader } from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";

Expand Down Expand Up @@ -329,7 +329,6 @@ const Outlet = () => {
value={{
imageLoader,
assetBaseUrl,
imageBaseUrl,
resources,
}}
>
Expand Down
6 changes: 3 additions & 3 deletions fixtures/webstudio-remix-netlify-functions/app/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ export const imageBaseUrl = "/assets/";
*/
export const imageLoader = (props) => {
if (process.env.NODE_ENV !== "production") {
return imageBaseUrl + props.src;
return assetBaseUrl + props.src;
}

if (props.format === "raw") {
return imageBaseUrl + props.src;
return assetBaseUrl + props.src;
}

// https://docs.netlify.com/image-cdn/overview/
return (
"/.netlify/images?url=" +
encodeURIComponent(imageBaseUrl + props.src) +
encodeURIComponent(assetBaseUrl + props.src) +
"&w=" +
props.width +
"&q=" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
projectId,
contactEmail,
} from "../__generated__/[another-page]._index.server";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";
import { assetBaseUrl, imageLoader } from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";

Expand Down Expand Up @@ -329,7 +329,6 @@ const Outlet = () => {
value={{
imageLoader,
assetBaseUrl,
imageBaseUrl,
resources,
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
projectId,
contactEmail,
} from "../__generated__/_index.server";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";
import { assetBaseUrl, imageLoader } from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";

Expand Down Expand Up @@ -329,7 +329,6 @@ const Outlet = () => {
value={{
imageLoader,
assetBaseUrl,
imageBaseUrl,
resources,
}}
>
Expand Down
6 changes: 3 additions & 3 deletions fixtures/webstudio-remix-vercel/app/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ export const imageBaseUrl = "/assets/";
*/
export const imageLoader = (props) => {
if (process.env.NODE_ENV !== "production") {
return imageBaseUrl + props.src;
return assetBaseUrl + props.src;
}

if (props.format === "raw") {
return imageBaseUrl + props.src;
return assetBaseUrl + props.src;
}

// https://vercel.com/blog/build-your-own-web-framework#automatic-image-optimization
return (
"/_vercel/image?url=" +
encodeURIComponent(imageBaseUrl + props.src) +
encodeURIComponent(assetBaseUrl + props.src) +
"&w=" +
props.width +
"&q=" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
projectId,
contactEmail,
} from "../__generated__/[_route_with_symbols_]._index.server";
import { assetBaseUrl, imageBaseUrl, imageLoader } from "../constants.mjs";
import { assetBaseUrl, imageLoader } from "../constants.mjs";
import css from "../__generated__/index.css?url";
import { sitemap } from "../__generated__/$resources.sitemap.xml";

Expand Down Expand Up @@ -329,7 +329,6 @@ const Outlet = () => {
value={{
imageLoader,
assetBaseUrl,
imageBaseUrl,
resources,
}}
>
Expand Down
Loading

0 comments on commit c1045ce

Please sign in to comment.