From 2898c2fb8d5b5cf8dfb3371c0b8e4682d932e46f Mon Sep 17 00:00:00 2001 From: Hexxa Date: Thu, 30 May 2024 16:20:08 +0800 Subject: [PATCH] fix: avoid rendering script by temporarily disable it (#7466) --- .../fixtures/after-response-collection.yaml | 1 + packages/insomnia/src/ui/routes/request.tsx | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/packages/insomnia-smoke-test/fixtures/after-response-collection.yaml b/packages/insomnia-smoke-test/fixtures/after-response-collection.yaml index 0b3f5825a09..c0c366ece59 100644 --- a/packages/insomnia-smoke-test/fixtures/after-response-collection.yaml +++ b/packages/insomnia-smoke-test/fixtures/after-response-collection.yaml @@ -70,6 +70,7 @@ resources: insomnia.environment.set('__fromAfterScript', 'environment'); insomnia.baseEnvironment.set('__fromAfterScript1', 'baseEnvironment'); insomnia.collectionVariables.set('__fromAfterScript2', 'collection'); + insomnia.environment.replaceIn('{{ $timestamp }}'); body: mimeType: "application/json" text: |- diff --git a/packages/insomnia/src/ui/routes/request.tsx b/packages/insomnia/src/ui/routes/request.tsx index cf12a2ba832..7bf84bb1029 100644 --- a/packages/insomnia/src/ui/routes/request.tsx +++ b/packages/insomnia/src/ui/routes/request.tsx @@ -370,6 +370,10 @@ export const sendAction: ActionFunction = async ({ request, params }) => { if (mutatedContext === null) { return null; } + // disable after-response script here to avoiding rendering it + const afterResponseScript = `${mutatedContext.request.afterResponseScript}`; + mutatedContext.request.afterResponseScript = ''; + const renderedResult = await tryToInterpolateRequest( mutatedContext.request, mutatedContext.environment, @@ -407,9 +411,12 @@ export const sendAction: ActionFunction = async ({ request, params }) => { const responsePatch = await responseTransform(response, requestData.activeEnvironmentId, renderedRequest, renderedResult.context); const is2XXWithBodyPath = responsePatch.statusCode && responsePatch.statusCode >= 200 && responsePatch.statusCode < 300 && responsePatch.bodyPath; const shouldWriteToFile = shouldPromptForPathAfterResponse && is2XXWithBodyPath; + + mutatedContext.request.afterResponseScript = afterResponseScript; if (requestData.request.afterResponseScript) { const baseEnvironment = await models.environment.getOrCreateForParentId(workspaceId); const cookieJar = await models.cookieJar.getOrCreateForParentId(workspaceId); + const postMutatedContext = await tryToExecuteAfterResponseScript({ ...requestData, ...mutatedContext,