Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Theme] Avoid breaking the document on Liquid syntax error #4583

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/late-steaks-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme': patch
---

Remove Liquid syntax error prettifier to avoid breaking the rest of the document.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {getClientScripts, HotReloadEvent} from './client.js'
import {render} from '../storefront-renderer.js'
import {patchRenderingResponse} from '../proxy.js'
import {prettifySyntaxErrors} from '../html.js'
import {getExtensionInMemoryTemplates} from '../../theme-ext-environment/theme-ext-server.js'
import {
createError,
Expand Down Expand Up @@ -238,8 +237,7 @@ export function getHotReloadHandler(theme: Theme, ctx: DevServerContext) {
})
}

const html = await patchRenderingResponse(ctx, event, response)
return prettifySyntaxErrors(html)
return patchRenderingResponse(ctx, event, response)
})
.catch(async (error: H3Error<{requestId?: string; url?: string}>) => {
let headline = `Failed to render section on Hot Reload with status ${error.statusCode} (${error.statusMessage}).`
Expand Down
20 changes: 0 additions & 20 deletions packages/theme/src/cli/utilities/theme-environment/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export function getHtmlHandler(theme: Theme, ctx: DevServerContext) {

let html = await patchRenderingResponse(ctx, event, response)

html = prettifySyntaxErrors(html)

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

if (ctx.options.liveReload !== 'off') {
Expand Down Expand Up @@ -86,24 +84,6 @@ function logRequestLine(event: H3Event, response: Response) {
)
}

export function prettifySyntaxErrors(html: string) {
return html.replace(/Liquid(?: syntax)? error \([^\n]+(?:\n|<)/g, getErrorSection)
}

function getErrorSection(error: string) {
const html = String.raw
const color = 'orangered'

return html`
<div
id="section-error"
style="border: solid thick ${color}; background: color(from ${color} srgb r g b / 0.2); padding: 20px;"
>
<pre>${error}</pre>
</div>
`
}

function getErrorPage(options: {title: string; header: string; message: string; code: string}) {
const html = String.raw

Expand Down
Loading