Skip to content

Commit ce93432

Browse files
authored
chore: optimize overlay page (#1908)
* chore: optimize overlay page * chore: update unless code * chore: remove benchmark ci * chore: bump runtime version
1 parent 615eec8 commit ce93432

File tree

5 files changed

+32
-115
lines changed

5 files changed

+32
-115
lines changed

.changeset/sharp-pugs-lie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@farmfe/runtime-plugin-hmr": major
3+
---
4+
5+
optimize runtime-hmr size

cspell.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"Aceternity",
1313
"ACVHU",
1414
"addtional",
15-
"arcgis",
1615
"Alexey",
1716
"Andale",
1817
"androideabi",
@@ -21,10 +20,12 @@
2120
"apng",
2221
"applescript",
2322
"AQDBI",
23+
"arcgis",
2424
"Architecure",
2525
"armv",
2626
"arraify",
2727
"assuptions",
28+
"atrule",
2829
"Avenir",
2930
"Bartosz",
3031
"Basepath",
@@ -99,6 +100,7 @@
99100
"Farmup",
100101
"feio",
101102
"fibo",
103+
"Fira",
102104
"flac",
103105
"flexbox",
104106
"fnames",
@@ -198,6 +200,7 @@
198200
"preact",
199201
"prefixer",
200202
"primevue",
203+
"prismjs",
201204
"procee",
202205
"proto",
203206
"protobuf",

packages/runtime-plugin-hmr/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"type-check": "tsc -p tsconfig.json --noEmit"
2525
},
2626
"devDependencies": {
27-
"@farmfe/runtime": "workspace:1.0.0-nightly-20241023020505"
27+
"@farmfe/runtime": "workspace:1.0.0-nightly-20241023020505",
28+
"@types/prismjs": "^1.26.5"
2829
},
2930
"dependencies": {
3031
"core-js": "^3.30.1",

packages/runtime-plugin-hmr/src/overlay.ts

Lines changed: 11 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {
77
stripAnsi
88
} from './utils';
99

10-
const base = '/';
11-
1210
// set :host styles to make playwright detect the element as visible
1311
const template = /*html*/ `
1412
<style>
@@ -130,8 +128,7 @@ code {
130128
131129
kbd {
132130
line-height: 1.5;
133-
font-family: ui-monospace, Menlo, Monaco, Consolas, 'Liberation Mono',
134-
'Courier New', monospace;
131+
font-family: ui-monospace, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
135132
font-size: 0.75rem;
136133
font-weight: 700;
137134
background-color: rgb(38, 40, 44);
@@ -141,8 +138,8 @@ kbd {
141138
border-width: 0.0625rem 0.0625rem 0.1875rem;
142139
border-style: solid;
143140
border-color: rgb(54, 57, 64);
144-
border-image: initial;
145141
}
142+
146143
.message-container {
147144
padding: 10px 10px;
148145
}
@@ -155,24 +152,6 @@ kbd {
155152
margin: 10px 0;
156153
}
157154
158-
159-
160-
kbd {
161-
line-height: 1.5;
162-
font-family: ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
163-
font-size: 0.75rem;
164-
font-weight: 700;
165-
background-color: rgb(38, 40, 44);
166-
color: rgb(166, 167, 171);
167-
padding: 0.15rem 0.3rem;
168-
border-radius: 0.25rem;
169-
border-width: 0.0625rem 0.0625rem 0.1875rem;
170-
border-style: solid;
171-
border-color: rgb(54, 57, 64);
172-
border-image: initial;
173-
}
174-
175-
176155
.code-block-wrapper {
177156
background-color: #282c34; /* Atom One Dark 背景色 */
178157
border-radius: 6px;
@@ -562,11 +541,7 @@ pre::-webkit-scrollbar-thumb:hover {
562541
</div>
563542
`;
564543

565-
const errorAlert = (
566-
message: string,
567-
description: string,
568-
_type: string
569-
) => /*html*/ `
544+
const errorAlert = (message: string, description: string) => /*html*/ `
570545
<div class="alert alert-error">
571546
<span class="alert-icon">
572547
<svg viewBox="64 64 896 896" focusable="false" data-icon="close-circle" width="1.2em" height="1.2em" fill="currentColor" aria-hidden="true">
@@ -580,20 +555,17 @@ const errorAlert = (
580555
</div>
581556
`;
582557

583-
const warnAlert = (description: string, type = 'warn') => /*html*/ `
584-
<div class="alert alert-${type}">
558+
const warnAlert = (description: string) => /*html*/ `
559+
<div class="alert alert-warn">
585560
<span class="alert-icon">
586-
${getAlertIcon(type)}
561+
${getAlertIcon('warn')}
587562
</span>
588563
<div class="alert-content">
589564
<div class="alert-description">${description.replace(/\n/g, '<br>')}</div>
590565
</div>
591566
</div>
592567
`;
593568

594-
const fileRE = /(?:[a-zA-Z]:\\|\/).*?:\d+:\d+/g;
595-
// const codeframeRE = /^(?:>?\s*\d+\s+\|.*|\s+\|\s*\^.*)\r?\n/gm;
596-
597569
// Allow `ErrorOverlay` to extend `HTMLElement` even in environments where
598570
// `HTMLElement` was not originally defined.
599571
const { HTMLElement = class {} as typeof globalThis.HTMLElement } = globalThis;
@@ -627,66 +599,6 @@ export class ErrorOverlay extends HTMLElement {
627599
document.addEventListener('keydown', this.closeOnEsc);
628600
}
629601

630-
text(selector: string, text: string, linkFiles = false): void {
631-
const el = this.root.querySelector(selector)!;
632-
if (!linkFiles) {
633-
el.textContent = text;
634-
} else {
635-
let curIndex = 0;
636-
let match: RegExpExecArray | null;
637-
fileRE.lastIndex = 0;
638-
while ((match = fileRE.exec(text))) {
639-
const { 0: file, index } = match;
640-
if (index != null) {
641-
const frag = text.slice(curIndex, index);
642-
el.appendChild(document.createTextNode(frag));
643-
const link = document.createElement('a');
644-
link.textContent = file;
645-
link.className = 'file-link';
646-
link.onclick = () => {
647-
fetch(
648-
new URL(
649-
`${base}__open-in-editor?file=${encodeURIComponent(file)}`,
650-
// import.meta.url
651-
window.location.href
652-
)
653-
);
654-
};
655-
el.appendChild(link);
656-
curIndex += frag.length + file.length;
657-
}
658-
}
659-
}
660-
}
661-
662-
setMessageText(element: HTMLElement, text: string, linkFiles: boolean) {
663-
if (!linkFiles) {
664-
element.textContent = text;
665-
} else {
666-
element.innerHTML = '';
667-
let lastIndex = 0;
668-
text.replace(fileRE, (file, index) => {
669-
if (index > lastIndex) {
670-
element.appendChild(
671-
document.createTextNode(text.substring(lastIndex, index))
672-
);
673-
}
674-
const link = document.createElement('a');
675-
link.textContent = file;
676-
link.className = 'file-link';
677-
link.onclick = () => {
678-
fetch(`${base}__open-in-editor?file=${encodeURIComponent(file)}`);
679-
};
680-
element.appendChild(link);
681-
lastIndex = index + file.length;
682-
return file;
683-
});
684-
if (lastIndex < text.length) {
685-
element.appendChild(document.createTextNode(text.substring(lastIndex)));
686-
}
687-
}
688-
}
689-
690602
highlightCode(code: string, language = 'javascript') {
691603
return Prism.highlight(code, Prism.languages[language], language);
692604
}
@@ -740,22 +652,16 @@ export class ErrorOverlay extends HTMLElement {
740652
msg = parseIfJSON(msg);
741653

742654
if (msg.type) {
743-
const TypeError = document.createElement('span');
744-
TypeError.className = 'type-error';
745-
TypeError.textContent = msg.type;
655+
const typeError = document.createElement('span');
656+
typeError.className = 'type-error';
657+
typeError.textContent = msg.type;
746658
const TypeCodeError = document.createElement('div');
747-
TypeCodeError.innerHTML = errorAlert(msg.type, msg.id, msg.type);
659+
TypeCodeError.innerHTML = errorAlert(msg.type, msg.id);
748660
messageElement.appendChild(TypeCodeError);
749661
}
750662

751-
// if (msg.plugin) {
752-
// const pluginElement = document.createElement('span');
753-
// pluginElement.className = 'plugin';
754-
// pluginElement.textContent = `[plugin:${msg.plugin}] `;
755-
// messageElement.appendChild(pluginElement);
756-
// }
757-
758663
const messageBody = document.createElement('div');
664+
759665
messageBody.className = 'message';
760666

761667
const splitMessage = splitErrorMessage(msg);
@@ -880,13 +786,6 @@ export class ErrorOverlay extends HTMLElement {
880786
messageContainer.appendChild(messageElement);
881787
}
882788

883-
// if (msg.stack) {
884-
// const stack = document.createElement('pre');
885-
// stack.className = 'stack';
886-
// this.setMessageText(stack, msg.stack, links);
887-
// messageElement.appendChild(stack);
888-
// }
889-
890789
if (msg.cause) {
891790
const causeElement = document.createElement('div');
892791
causeElement.innerHTML = warnAlert(msg.cause);

pnpm-lock.yaml

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)