1
- import { Component , createEffect , createSignal , splitProps , JSX , onMount } from 'solid-js' ;
1
+ import { Component , createEffect , createSignal , splitProps , JSX , onMount , onCleanup } from 'solid-js' ;
2
2
import { useZoom } from '../hooks/useZoom' ;
3
3
4
4
export const Preview : Component < Props > = ( props ) => {
@@ -21,7 +21,14 @@ export const Preview: Component<Props> = (props) => {
21
21
if ( isNotDom || isEmpty || ! isIframeReady ( ) ) return ;
22
22
23
23
latestCode = internal . code . replace ( 'render(' , 'window.dispose = render(' ) ;
24
- iframe . contentWindow ! . postMessage ( { event : CODE_UPDATE , code : latestCode } , '*' ) ;
24
+
25
+ const blob = new Blob ( [ latestCode ] , {
26
+ type : 'text/javascript' ,
27
+ } ) ;
28
+ const src = URL . createObjectURL ( blob ) ;
29
+ onCleanup ( ( ) => URL . revokeObjectURL ( src ) ) ;
30
+
31
+ iframe . contentWindow ! . postMessage ( { event : CODE_UPDATE , code : src } , '*' ) ;
25
32
} ) ;
26
33
27
34
createEffect ( ( ) => {
@@ -49,7 +56,7 @@ export const Preview: Component<Props> = (props) => {
49
56
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
50
57
51
58
<!-- Ressource hints -->
52
- <link rel="dns-prefetch" href="//unpkg.com">
59
+ <link rel="dns-prefetch" href="https: //unpkg.com">
53
60
<link href="https://unpkg.com" rel="preconnect" crossorigin>
54
61
<link rel="preload" href="https://unpkg.com/[email protected] /modern-normalize.css" as="style">
55
62
<link href="https://unpkg.com/[email protected] /modern-normalize.css" rel="stylesheet">
@@ -115,7 +122,7 @@ export const Preview: Component<Props> = (props) => {
115
122
eruda.position({ x: window.innerWidth - 30, y: window.innerHeight - 30 });
116
123
const style = Object.assign(document.createElement('link'), {
117
124
rel: 'stylesheet',
118
- href: '/eruda.css'
125
+ href: '${ location . origin } /eruda.css'
119
126
});
120
127
eruda._shadowRoot.appendChild(style);
121
128
if (${ internal . devtools } ) eruda.show();
@@ -147,9 +154,7 @@ export const Preview: Component<Props> = (props) => {
147
154
148
155
console.clear();
149
156
150
- const encodedCode = encodeURIComponent(code);
151
- const dataUri = 'data:text/javascript;charset=utf-8,' + encodedCode;
152
- await import(dataUri);
157
+ await import(code);
153
158
154
159
const load = document.getElementById('load');
155
160
if (code && load) load.remove();
@@ -168,14 +173,19 @@ export const Preview: Component<Props> = (props) => {
168
173
</body>
169
174
</html>
170
175
` ;
176
+ const blob = new Blob ( [ html ] , {
177
+ type : 'text/html' ,
178
+ } ) ;
179
+ const src = URL . createObjectURL ( blob ) ;
180
+ onCleanup ( ( ) => URL . revokeObjectURL ( src ) ) ;
171
181
172
182
createEffect ( ( ) => {
173
183
// Bail early on first mount or we are already reloading
174
184
if ( ! internal . reloadSignal ) return ;
175
185
176
186
// Otherwise, reload everytime we clicked the reload button
177
187
setIframeReady ( false ) ;
178
- iframe . srcdoc = html ;
188
+ iframe . src = src ;
179
189
} ) ;
180
190
181
191
const styleScale = ( ) => {
@@ -187,7 +197,6 @@ export const Preview: Component<Props> = (props) => {
187
197
} ;
188
198
189
199
onMount ( ( ) => {
190
- iframe . srcdoc = html ;
191
200
iframe . addEventListener ( 'load' , ( ) => {
192
201
setIframeReady ( true ) ;
193
202
@@ -205,6 +214,7 @@ export const Preview: Component<Props> = (props) => {
205
214
title = "Solid REPL"
206
215
class = "overflow-auto p-0 w-full h-full dark:bg-other block"
207
216
ref = { iframe }
217
+ src = { src }
208
218
// @ts -ignore
209
219
sandbox = "allow-popups-to-escape-sandbox allow-scripts allow-popups allow-forms allow-pointer-lock allow-top-navigation allow-modals allow-same-origin"
210
220
> </ iframe >
0 commit comments