Skip to content

Commit 25895a2

Browse files
clyde-builderioClyde Mendonca
andauthored
fix[gen1+gen2][httpRequests]: ENG-9530 improved implementation of making Content http-requests with GET method (BuilderIO#4087)
## Description Improved implementation of making Content http-requests with GET method **JIRA ticket** https://builder-io.atlassian.net/browse/ENG-9530 Co-authored-by: Clyde Mendonca <[email protected]>
1 parent 7adc4f6 commit 25895a2

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

.changeset/soft-spoons-serve.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@builder.io/react": patch
3+
"@builder.io/sdk-angular": patch
4+
"@builder.io/sdk-react-nextjs": patch
5+
"@builder.io/sdk-qwik": patch
6+
"@builder.io/sdk-react": patch
7+
"@builder.io/sdk-react-native": patch
8+
"@builder.io/sdk-solid": patch
9+
---
10+
11+
Fix: Improved implementation of making Content http-requests with GET method

packages/react/src/components/builder-component.component.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,11 +1279,15 @@ export class BuilderComponent extends React.Component<
12791279
}
12801280
let json: any;
12811281
try {
1282-
const result = await fetch(url, {
1282+
const fetchOptions = {
12831283
method,
12841284
headers,
1285-
body: method === 'GET' ? undefined : body,
1286-
});
1285+
body,
1286+
};
1287+
if (method === 'GET') {
1288+
delete fetchOptions.body;
1289+
}
1290+
const result = await fetch(url, fetchOptions);
12871291
json = await result.json();
12881292
} catch (err) {
12891293
const error = toError(err);

packages/sdks/src/components/content/components/enable-editor.lite.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,16 @@ export default function EnableEditor(props: BuilderEditorProps) {
243243

244244
logFetch(JSON.stringify(fetchRequestObj));
245245

246-
fetch(fetchRequestObj.url, {
246+
const fetchOptions = {
247247
method: fetchRequestObj.method,
248248
headers: fetchRequestObj.headers,
249-
body:
250-
fetchRequestObj.method === 'GET'
251-
? undefined
252-
: fetchRequestObj.body,
253-
})
249+
body: fetchRequestObj.body,
250+
};
251+
if (fetchRequestObj.method === 'GET') {
252+
delete fetchOptions.body;
253+
}
254+
255+
fetch(fetchRequestObj.url, fetchOptions)
254256
.then((response) => response.json())
255257
.then((json) => {
256258
state.mergeNewRootState({ [key]: json });

0 commit comments

Comments
 (0)