Skip to content

Commit 069376f

Browse files
authored
fix: Rate limit on shared link clicks (#4715)
## Description closes #4403 We have no way to show good errors on naviagation errors (remix does not support this) Here I reduced amount of reloads on link clicks on preview ## 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 050b9bd commit 069376f

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

apps/builder/app/root.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// Our root outlet doesn't contain a layout because we have 2 types of documents: canvas and builder and we need to decide down the line which one to render, thre is no single root document.
2-
import { Outlet, json, useLoaderData } from "@remix-run/react";
2+
import {
3+
Outlet,
4+
json,
5+
useLoaderData,
6+
type ShouldRevalidateFunction,
7+
} from "@remix-run/react";
38
import { setEnv } from "@webstudio-is/feature-flags";
49
import env from "./env/env.server";
510
import { useSetFeatures } from "./shared/use-set-features";
@@ -17,3 +22,7 @@ export default function App() {
1722

1823
return <Outlet />;
1924
}
25+
26+
export const shouldRevalidate: ShouldRevalidateFunction = () => {
27+
return false;
28+
};

apps/builder/app/routes/_ui.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Scripts,
66
ScrollRestoration,
77
type ClientLoaderFunctionArgs,
8+
type ShouldRevalidateFunction,
89
} from "@remix-run/react";
910
import interFont from "@fontsource-variable/inter/index.css?url";
1011
import manropeVariableFont from "@fontsource-variable/manrope/index.css?url";
@@ -106,3 +107,7 @@ export default function Layout() {
106107
</Document>
107108
);
108109
}
110+
111+
export const shouldRevalidate: ShouldRevalidateFunction = () => {
112+
return false;
113+
};

apps/builder/app/shared/nano-states/props.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,12 @@ export const subscribeResources = () => {
718718
cacheByKeys.set(cacheKey, undefined);
719719
}
720720

721-
const result = await loadResources(Array.from(missing.values()));
721+
const missingValues = Array.from(missing.values());
722+
if (missingValues.length === 0) {
723+
return;
724+
}
725+
726+
const result = await loadResources(missingValues);
722727
const newResourceValues = new Map();
723728
for (const request of computedResources) {
724729
const cacheKey = JSON.stringify(request);

0 commit comments

Comments
 (0)