Skip to content

Commit 2ad9807

Browse files
committed
perf: optimize instance preview.
1 parent 679d07c commit 2ad9807

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/index.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ export default React.forwardRef<HTMLIFrameElement, RunWebProps>((props, ref) =>
1616

1717
useImperativeHandle(ref, () => frameRef.current as HTMLIFrameElement, [frameRef]);
1818

19-
const srcDoc = useMemo(() => {
19+
useMemo(() => {
2020
setIsLoaded(false);
2121
const jsString = js ? `<script type="text/javascript">${js}</script>` : '';
2222
const cssString = css ? `<style>${css}</style>` : '';
23-
return `<!DOCTYPE html><html><head>${cssString}</head><body>${html}</body>${jsString}</html>`;
23+
const result = `<!DOCTYPE html><html><head>${cssString}</head><body>${html}</body>${jsString}</html>`;
24+
const blob = new Blob([result], { type: 'text/html' });
25+
if (frameRef.current) {
26+
frameRef.current.src = URL.createObjectURL(blob);
27+
}
2428
}, [css, html, js]);
2529

2630
function renderFrameContents() {
@@ -40,7 +44,6 @@ export default React.forwardRef<HTMLIFrameElement, RunWebProps>((props, ref) =>
4044
onLoad && onLoad(evn);
4145
}}
4246
ref={frameRef}
43-
srcDoc={srcDoc}
4447
>
4548
{isLoaded && renderFrameContents()}
4649
</iframe>

website/pages/run/index.module.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
}
2929

3030
.editor {
31-
font-size: 12px;
31+
font-size: 16px;
3232
background-color: #fff;
3333
position: relative;
3434
overflow: hidden;

website/pages/run/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default function Run() {
7878
<div className={styles.editorCode}>
7979
<CodeEditor
8080
value={htmlStr}
81-
style={{ minHeight: '100%' }}
81+
style={{ fontSize: 16, minHeight: '100%' }}
8282
placeholder="Please enter HTML code."
8383
onChange={(evn) => handleChange(evn.target.value, 'html')}
8484
language="html"
@@ -96,7 +96,7 @@ export default function Run() {
9696
<div className={styles.editorCode}>
9797
<CodeEditor
9898
value={jsStr}
99-
style={{ minHeight: '100%' }}
99+
style={{ fontSize: 16, minHeight: '100%' }}
100100
placeholder="Please enter JavaScript code."
101101
onChange={(evn) => handleChange(evn.target.value, 'js')}
102102
language="js"
@@ -114,7 +114,7 @@ export default function Run() {
114114
<div className={styles.editorCode}>
115115
<CodeEditor
116116
value={cssStr}
117-
style={{ minHeight: '100%' }}
117+
style={{ fontSize: 16, minHeight: '100%' }}
118118
placeholder="Please enter CSS code."
119119
onChange={(evn) => handleChange(evn.target.value, 'css')}
120120
language="css"

0 commit comments

Comments
 (0)