Skip to content

Commit 8d4dd50

Browse files
authored
Merge pull request #6264 from Shopify/patch-304-response
Fix an error related to patched 304 status responses when running theme dev
2 parents eaa8774 + d2ad0b4 commit 8d4dd50

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

.changeset/fair-parents-reply.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/theme': patch
3+
---
4+
5+
Fixed theme dev error on HTTP 304 patched responses

packages/theme/src/cli/utilities/theme-environment/proxy.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,26 @@ describe('dev proxy', () => {
197197
// Stores _shopify_essential for the following requests
198198
expect(ctx.session.sessionCookies).toHaveProperty('_shopify_essential', ':AZFbAlZ..yAAH:')
199199
})
200+
201+
test('handles 304 Not Modified responses without crashing', async () => {
202+
// Create 304 response with no body as per HTTP spec
203+
const notModifiedResponse = new Response(null, {
204+
status: 304,
205+
statusText: 'Not Modified',
206+
headers: {
207+
etag: '"abc123"',
208+
'cache-control': 'max-age=3600',
209+
'x-request-id': 'test-123',
210+
},
211+
})
212+
213+
const result = await patchRenderingResponse(ctx, notModifiedResponse)
214+
215+
expect(result.status).toBe(304)
216+
expect(result.statusText).toBe('Not Modified')
217+
expect(result.headers.get('etag')).toBe('"abc123"')
218+
expect(result.body).toBeNull()
219+
})
200220
})
201221

202222
describe('getProxyStorefrontHeaders', () => {

packages/theme/src/cli/utilities/theme-environment/proxy.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ export async function patchRenderingResponse(
172172
rawResponse: Response,
173173
patchCallback?: (html: string) => string | undefined,
174174
): Promise<Response> {
175+
// 3xx responses should be returned
176+
if (rawResponse.status >= 300 && rawResponse.status < 400) {
177+
return rawResponse
178+
}
179+
175180
const response = patchProxiedResponseHeaders(ctx, rawResponse)
176181

177182
// Only set HTML content-type for actual HTML responses, preserve JSON content-type:

0 commit comments

Comments
 (0)