Skip to content

Commit 599cdd2

Browse files
committed
Refactor: Move asset upload error page rendering prior to the render call to SFR
1 parent e771c6b commit 599cdd2

File tree

1 file changed

+27
-14
lines changed
  • packages/theme/src/cli/utilities/theme-environment

1 file changed

+27
-14
lines changed

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

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {render} from './storefront-renderer.js'
44
import {getErrorPage} from './hot-reload/error-page.js'
55
import {getExtensionInMemoryTemplates} from '../theme-ext-environment/theme-ext-server.js'
66
import {logRequestLine} from '../log-request-line.js'
7-
import {defineEventHandler, getCookie, setResponseHeader, setResponseStatus, type H3Error} from 'h3'
7+
import {defineEventHandler, getCookie, H3Event, setResponseHeader, setResponseStatus, type H3Error} from 'h3'
88
import {renderError, renderFatalError} from '@shopify/cli-kit/node/ui'
99
import {AbortError} from '@shopify/cli-kit/node/error'
1010
import type {Response} from '@shopify/cli-kit/node/http'
@@ -15,6 +15,13 @@ export function getHtmlHandler(theme: Theme, ctx: DevServerContext) {
1515
return defineEventHandler((event) => {
1616
const [browserPathname = '/', browserSearch = ''] = event.path.split('?')
1717

18+
const shouldRenderUploadErrorPage =
19+
ctx.options.errorOverlay !== 'silent' && ctx.localThemeFileSystem.uploadErrors.size > 0
20+
21+
if (shouldRenderUploadErrorPage) {
22+
return renderUploadErrorPage(ctx, event)
23+
}
24+
1825
return render(ctx.session, {
1926
method: event.method,
2027
path: browserPathname,
@@ -32,19 +39,6 @@ export function getHtmlHandler(theme: Theme, ctx: DevServerContext) {
3239

3340
assertThemeId(response, html, String(theme.id))
3441

35-
if (ctx.options.errorOverlay !== 'silent' && ctx.localThemeFileSystem.uploadErrors.size > 0) {
36-
setResponseStatus(event, 500, 'Failed to Upload Theme Files')
37-
setResponseHeader(event, 'Content-Type', 'text/html')
38-
html = getErrorPage({
39-
title: 'Failed to Upload Theme Files',
40-
header: 'Upload Errors',
41-
errors: Array.from(ctx.localThemeFileSystem.uploadErrors.entries()).map(([file, errors]) => ({
42-
message: file,
43-
code: errors.join('\n'),
44-
})),
45-
})
46-
}
47-
4842
if (ctx.options.liveReload !== 'off') {
4943
html = injectHotReloadScript(html)
5044
}
@@ -83,6 +77,25 @@ export function getHtmlHandler(theme: Theme, ctx: DevServerContext) {
8377
})
8478
}
8579

80+
function renderUploadErrorPage(ctx: DevServerContext, event: H3Event) {
81+
setResponseStatus(event, 500, 'Failed to Upload Theme Files')
82+
setResponseHeader(event, 'Content-Type', 'text/html')
83+
let html = getErrorPage({
84+
title: 'Failed to Upload Theme Files',
85+
header: 'Upload Errors',
86+
errors: Array.from(ctx.localThemeFileSystem.uploadErrors.entries()).map(([file, errors]) => ({
87+
message: file,
88+
code: errors.join('\n'),
89+
})),
90+
})
91+
92+
if (ctx.options.liveReload !== 'off') {
93+
html = injectHotReloadScript(html)
94+
}
95+
96+
return html
97+
}
98+
8699
function assertThemeId(response: Response, html: string, expectedThemeId: string) {
87100
/**
88101
* DOM example:

0 commit comments

Comments
 (0)