File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed
packages/theme/src/cli/utilities/theme-environment Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @shopify/theme ' : patch
3+ ---
4+
5+ Fixed theme dev error on HTTP 304 patched responses
Original file line number Diff line number Diff 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' , ( ) => {
Original file line number Diff line number Diff 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:
You can’t perform that action at this time.
0 commit comments