Skip to content

Commit 05d8baf

Browse files
authored
fix: reduce patch size to let users duplicate huge pages (#5400)
User is trying to duplicate huge page and gets "413 Content Too Large". Here I'm trying to reduce patch request size by removing revise patches which are not used on server.
1 parent 62f969c commit 05d8baf

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

apps/builder/app/builder/shared/sync/sync-server.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,18 @@ const syncServer = async function () {
168168
if (details.authToken) {
169169
headers.append("x-auth-token", details.authToken);
170170
}
171+
// revise patches are not used on the server and reduce possible patch size
172+
const optimizedTransactions = transactions.map((transaction) => ({
173+
...transaction,
174+
payload: transaction.payload.map((change) => ({
175+
namespace: change.namespace,
176+
patches: change.patches,
177+
})),
178+
}));
171179
const response = await fetch(restPatchPath(), {
172180
method: "post",
173181
body: JSON.stringify({
174-
transactions,
182+
transactions: optimizedTransactions,
175183
buildId: details.buildId,
176184
projectId,
177185
// provide latest stored version to server

apps/builder/app/routes/rest.patch.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { applyPatches, enableMapSet, enablePatches } from "immer";
1+
import { applyPatches, enableMapSet, enablePatches, type Patch } from "immer";
22
import type { ActionFunctionArgs } from "@remix-run/server-runtime";
3-
import type { Change } from "immerhin";
43
import {
54
Breakpoints,
65
Breakpoint,
@@ -51,6 +50,11 @@ import { preventCrossOriginCookie } from "~/services/no-cross-origin-cookie";
5150
import { checkCsrf } from "~/services/csrf-session.server";
5251
import type { Transaction } from "~/shared/sync-client";
5352

53+
type Change = {
54+
namespace: string;
55+
patches: Array<Patch>;
56+
};
57+
5458
type PatchData = {
5559
transactions: Transaction<Change[]>[];
5660
buildId: Build["id"];

0 commit comments

Comments
 (0)