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 @@ -171,6 +171,11 @@ export async function patchRenderingResponse(
171171 rawResponse : Response ,
172172 patchCallback ?: ( html : string ) => string | undefined ,
173173) : Promise < Response > {
174+ // 3xx responses should be returned
175+ if ( rawResponse . status >= 300 && rawResponse . status < 400 ) {
176+ return rawResponse
177+ }
178+
174179 const response = patchProxiedResponseHeaders ( ctx , rawResponse )
175180
176181 // 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