Skip to content

Commit a068bc9

Browse files
authored
experimental: Error support on components level (#5136)
## Description Error toasts in components instead of failing ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 0e5d4f7 commit a068bc9

File tree

36 files changed

+52
-1
lines changed

36 files changed

+52
-1
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ jobs:
133133
}
134134
}
135135
const results = [
136-
await assertSize('./fixtures/ssg/dist/client', 352),
136+
await assertSize('./fixtures/ssg/dist/client', 356),
137137
await assertSize('./fixtures/react-router-netlify/build/client', 368),
138138
await assertSize('./fixtures/webstudio-features/build/client', 1052),
139139
]

apps/builder/app/canvas/canvas.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import { createInstanceElement } from "./elements";
7777
import { Body } from "./shared/body";
7878
import { subscribeScrollbarSize } from "./scrollbar-width";
7979
import { compareMedia } from "@webstudio-is/css-engine";
80+
import { builderApi } from "~/shared/builder-api";
8081

8182
registerContainers();
8283

@@ -98,6 +99,16 @@ const FallbackComponent = ({ error, resetErrorBoundary }: FallbackProps) => {
9899
);
99100
};
100101

102+
const handleError = (error: unknown) => {
103+
if (error instanceof Error) {
104+
builderApi.toast.error(error.message);
105+
return;
106+
}
107+
108+
builderApi.toast.error(`Unknown error: ${String(error)}`);
109+
console.error(error);
110+
};
111+
101112
const useElementsTree = (components: Components, instances: Instances) => {
102113
const page = useStore($selectedPage);
103114
const isPreviewMode = useStore($isPreviewMode);
@@ -128,6 +139,8 @@ const useElementsTree = (components: Components, instances: Instances) => {
128139
imageLoader: wsImageLoader,
129140
resources: {},
130141
breakpoints,
142+
// error reporting
143+
onError: handleError,
131144
}}
132145
>
133146
{createInstanceElement({

fixtures/react-router-docker/app/routes/[another-page]._index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ const Outlet = () => {
274274
assetBaseUrl,
275275
resources,
276276
breakpoints,
277+
onError: console.error,
277278
}}
278279
>
279280
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}

fixtures/react-router-docker/app/routes/_index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ const Outlet = () => {
274274
assetBaseUrl,
275275
resources,
276276
breakpoints,
277+
onError: console.error,
277278
}}
278279
>
279280
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}

fixtures/react-router-netlify/app/routes/[another-page]._index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ const Outlet = () => {
274274
assetBaseUrl,
275275
resources,
276276
breakpoints,
277+
onError: console.error,
277278
}}
278279
>
279280
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}

fixtures/react-router-netlify/app/routes/_index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ const Outlet = () => {
274274
assetBaseUrl,
275275
resources,
276276
breakpoints,
277+
onError: console.error,
277278
}}
278279
>
279280
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}

fixtures/react-router-vercel/app/routes/[another-page]._index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ const Outlet = () => {
274274
assetBaseUrl,
275275
resources,
276276
breakpoints,
277+
onError: console.error,
277278
}}
278279
>
279280
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}

fixtures/react-router-vercel/app/routes/_index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ const Outlet = () => {
274274
assetBaseUrl,
275275
resources,
276276
breakpoints,
277+
onError: console.error,
277278
}}
278279
>
279280
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}

fixtures/ssg-netlify-by-project-id/pages/index/+Page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const PageComponent = ({ data }: { data: PageContext["data"] }) => {
1212
assetBaseUrl,
1313
resources,
1414
breakpoints,
15+
onError: console.error,
1516
}}
1617
>
1718
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}

fixtures/ssg/pages/another-page/+Page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const PageComponent = ({ data }: { data: PageContext["data"] }) => {
1515
assetBaseUrl,
1616
resources,
1717
breakpoints,
18+
onError: console.error,
1819
}}
1920
>
2021
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}

0 commit comments

Comments
 (0)