-
Notifications
You must be signed in to change notification settings - Fork 184
[Feature] Render error page when theme dev
encounters asset upload error
#5221
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
45d29fc
Render error page on theme asset upload error
jamesmengo b2f0ae1
Trigger full reload when error overlay needs to be updated
jamesmengo f26ff7f
Add 'error-overlay' flag to `theme dev` command to toggle error overl…
jamesmengo 1761d5e
Bugfix - Escape HTML in error messages
jamesmengo fca9c19
Changeset + docs
jamesmengo e771c6b
Return 500 status when asset upload error page is rendered
jamesmengo 599cdd2
Refactor: Move asset upload error page rendering prior to the render …
jamesmengo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@shopify/theme': minor | ||
--- | ||
|
||
Render error overlay when `theme dev` encounters asset upload errors. A 500 status code is returned when the error overlay is rendered. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
packages/theme/src/cli/utilities/theme-environment/hot-reload/error-page.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
interface Error { | ||
message: string | ||
code: string | ||
} | ||
|
||
const POLARIS_STYLESHEET_URL = 'https://unpkg.com/@shopify/[email protected]/build/esm/styles.css' | ||
karreiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function escapeHtml(unsafe: string) { | ||
return unsafe | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, ''') | ||
} | ||
|
||
export function getErrorPage(options: {title: string; header: string; errors: Error[]}) { | ||
const html = String.raw | ||
return html`<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>${options.title ?? 'Upload Errors'}</title> | ||
<link rel="stylesheet" href="${POLARIS_STYLESHEET_URL}" /> | ||
</head> | ||
<body> | ||
<div style="display: flex; justify-content: center; padding-top: 2rem;"> | ||
<div style="width: 80%;"> | ||
<div class="Polaris-Banner Polaris-Banner--withinPage" tabindex="0" role="alert" aria-live="polite"> | ||
<div class="Polaris-Box" style="--pc-box-width:100%"> | ||
<div | ||
class="Polaris-BlockStack" | ||
style="--pc-block-stack-align:space-between;--pc-block-stack-order:column" | ||
> | ||
<div | ||
class="Polaris-Box" | ||
style="--pc-box-color: var(--p-color-text-critical-on-bg-fill); --pc-box-background: var(--p-color-bg-fill-critical); --pc-box-padding-block-start-xs: var(--p-space-300); --pc-box-padding-block-end-xs: var(--p-space-300); --pc-box-padding-inline-start-xs: var(--p-space-300); --pc-box-padding-inline-end-xs: var(--p-space-300); --pc-box-border-start-start-radius: var(--p-border-radius-300); --pc-box-border-start-end-radius: var(--p-border-radius-300);" | ||
> | ||
<div | ||
class="Polaris-InlineStack" | ||
style="--pc-inline-stack-align:space-between;--pc-inline-stack-block-align:center;--pc-inline-stack-wrap:nowrap;--pc-inline-stack-gap-xs:var(--p-space-200);--pc-inline-stack-flex-direction-xs:row" | ||
> | ||
<div | ||
class="Polaris-InlineStack" | ||
style="--pc-inline-stack-wrap:nowrap;--pc-inline-stack-gap-xs:var(--p-space-100);--pc-inline-stack-flex-direction-xs:row" | ||
> | ||
<span class="Polaris-Banner--textCriticalOnBgFill"> | ||
<span class="Polaris-Icon"> | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"> | ||
<path d="M10 6a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5a.75.75 0 0 1 .75-.75Z" /> | ||
<path d="M11 13a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z" /> | ||
<path | ||
fill-rule="evenodd" | ||
d="M17 10a7 7 0 1 1-14 0 7 7 0 0 1 14 0Zm-1.5 0a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0Z" | ||
/> | ||
</svg> | ||
</span> | ||
</span> | ||
<h2 class="Polaris-Text--root Polaris-Text--headingSm Polaris-Text--break"> | ||
${options.header} | ||
</h2> | ||
</div> | ||
</div> | ||
</div> | ||
<div | ||
class="Polaris-Box" | ||
style="--pc-box-padding-block-start-xs:var(--p-space-300);--pc-box-padding-block-end-xs:var(--p-space-300);--pc-box-padding-block-end-md:var(--p-space-400);--pc-box-padding-inline-start-xs:var(--p-space-300);--pc-box-padding-inline-start-md:var(--p-space-400);--pc-box-padding-inline-end-xs:var(--p-space-300);--pc-box-padding-inline-end-md:var(--p-space-400)" | ||
> | ||
<div | ||
class="Polaris-BlockStack" | ||
style="--pc-block-stack-order:column;--pc-block-stack-gap-xs:var(--p-space-300)" | ||
> | ||
${options.errors | ||
.map( | ||
(error) => ` | ||
<div> | ||
<span class="Polaris-Text--root Polaris-Text--headingSm">${escapeHtml(error.message)}</span> | ||
<ul class="Polaris-List"> | ||
<li class="Polaris-List__Item">${escapeHtml(error.code)}</li> | ||
</ul> | ||
</div>`, | ||
) | ||
.join('')} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
</html>` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing values, should we pass
allowNo: true
so that devs can use the flag as--no-error-overlay
to disable the behavior? Or do we expect to have more options in the future?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, the idea is to leave room for expansion moving forward, though there's no clear timeline for that so perhaps something we could call into question