|
1 | 1 | import { component$, useComputed$ } from '@qwik.dev/core';
|
2 | 2 | import { CodeBlock } from '../components/code-block/code-block';
|
3 | 3 | import { ReplOutputModules } from './repl-output-modules';
|
4 |
| -import { ReplOutputSegments } from './repl-output-segments.tsx'; |
| 4 | +import { ReplOutputSegments } from './repl-output-segments'; |
5 | 5 | import { ReplTabButton } from './repl-tab-button';
|
6 | 6 | import { ReplTabButtons } from './repl-tab-buttons';
|
7 | 7 | import type { ReplAppInput, ReplStore } from './types';
|
8 | 8 | import { _deserialize, _getDomContainer } from '@qwik.dev/core/internal';
|
9 |
| -import { dumpState, preprocessState } from '../../../qwik/src/core/shared/shared-serialization.ts'; |
10 |
| -import { vnode_toString } from '../../../qwik/src/core/client/vnode.ts'; |
| 9 | +import { dumpState, preprocessState } from '../../../qwik/src/core/shared/shared-serialization'; |
| 10 | +import { vnode_toString } from '../../../qwik/src/core/client/vnode'; |
11 | 11 |
|
12 | 12 | export const ReplOutputPanel = component$(({ input, store }: ReplOutputPanelProps) => {
|
13 | 13 | const diagnosticsLen = useComputed$(
|
14 | 14 | () => store.diagnostics.length + store.monacoDiagnostics.length
|
15 | 15 | );
|
16 | 16 |
|
17 | 17 | const domContainerFromResultHtml = useComputed$(() => {
|
18 |
| - const parser = new DOMParser(); |
19 |
| - const doc = parser.parseFromString(store.htmlResult.rawHtml, 'text/html'); |
20 |
| - return _getDomContainer(doc.documentElement); |
| 18 | + try { |
| 19 | + const parser = new DOMParser(); |
| 20 | + const doc = parser.parseFromString(store.htmlResult.rawHtml, 'text/html'); |
| 21 | + return _getDomContainer(doc.documentElement); |
| 22 | + } catch (err) { |
| 23 | + console.error(err); |
| 24 | + return null; |
| 25 | + } |
21 | 26 | });
|
22 | 27 |
|
23 | 28 | const parsedState = useComputed$(() => {
|
24 |
| - const container = domContainerFromResultHtml.value; |
25 |
| - const doc = container.element; |
26 |
| - const qwikStates = doc.querySelectorAll('script[type="qwik/state"]'); |
27 |
| - if (qwikStates.length !== 0) { |
28 |
| - const data = qwikStates[qwikStates.length - 1]; |
29 |
| - const origState = JSON.parse(data?.textContent || '[]'); |
30 |
| - preprocessState(origState, container as any); |
31 |
| - return origState |
32 |
| - ? dumpState(origState, false, '', null) |
33 |
| - //remove first new line |
34 |
| - .replace(/\n/, '') |
35 |
| - : 'No state found'; |
| 29 | + try { |
| 30 | + const container = domContainerFromResultHtml.value; |
| 31 | + const doc = container!.element; |
| 32 | + const qwikStates = doc.querySelectorAll('script[type="qwik/state"]'); |
| 33 | + if (qwikStates.length !== 0) { |
| 34 | + const data = qwikStates[qwikStates.length - 1]; |
| 35 | + const origState = JSON.parse(data?.textContent || '[]'); |
| 36 | + preprocessState(origState, container as any); |
| 37 | + return origState |
| 38 | + ? dumpState(origState, false, '', null) |
| 39 | + //remove first new line |
| 40 | + .replace(/\n/, '') |
| 41 | + : 'No state found'; |
| 42 | + } |
| 43 | + return 'No state found'; |
| 44 | + } catch (err) { |
| 45 | + console.error(err); |
| 46 | + return null; |
36 | 47 | }
|
37 |
| - return 'No state found'; |
38 | 48 | });
|
39 | 49 |
|
40 | 50 | const vdomTree = useComputed$(() => {
|
41 |
| - const container = domContainerFromResultHtml.value; |
42 |
| - return vnode_toString.call( |
43 |
| - container.rootVNode as any, |
44 |
| - Number.MAX_SAFE_INTEGER, |
45 |
| - '', |
46 |
| - true, |
47 |
| - false, |
48 |
| - false |
49 |
| - ); |
| 51 | + try { |
| 52 | + const container = domContainerFromResultHtml.value; |
| 53 | + return vnode_toString.call( |
| 54 | + container!.rootVNode as any, |
| 55 | + Number.MAX_SAFE_INTEGER, |
| 56 | + '', |
| 57 | + true, |
| 58 | + false, |
| 59 | + false |
| 60 | + ); |
| 61 | + } catch (err) { |
| 62 | + console.error(err); |
| 63 | + return null; |
| 64 | + } |
50 | 65 | });
|
51 | 66 |
|
52 | 67 | return (
|
@@ -144,16 +159,23 @@ export const ReplOutputPanel = component$(({ input, store }: ReplOutputPanelProp
|
144 | 159 | <div class="output-result output-html flex flex-col gap-2">
|
145 | 160 | <div>
|
146 | 161 | <span class="code-block-info">HTML</span>
|
147 |
| - <CodeBlock language="markup" code={store.htmlResult.prettyHtml} /> |
148 |
| - </div> |
149 |
| - <div> |
150 |
| - <span class="code-block-info">Parsed State</span> |
151 |
| - <CodeBlock language="clike" code={parsedState.value} /> |
152 |
| - </div> |
153 |
| - <div> |
154 |
| - <span class="code-block-info">VNode Tree</span> |
155 |
| - <CodeBlock language="markup" code={vdomTree.value} /> |
| 162 | + <CodeBlock |
| 163 | + language="markup" |
| 164 | + code={store.htmlResult.prettyHtml || store.htmlResult.rawHtml} |
| 165 | + /> |
156 | 166 | </div>
|
| 167 | + {parsedState.value ? ( |
| 168 | + <div> |
| 169 | + <span class="code-block-info">Parsed State</span> |
| 170 | + <CodeBlock language="clike" code={parsedState.value} /> |
| 171 | + </div> |
| 172 | + ) : null} |
| 173 | + {vdomTree.value ? ( |
| 174 | + <div> |
| 175 | + <span class="code-block-info">VNode Tree</span> |
| 176 | + <CodeBlock language="markup" code={vdomTree.value} /> |
| 177 | + </div> |
| 178 | + ) : null} |
157 | 179 | </div>
|
158 | 180 | ) : null}
|
159 | 181 |
|
|
0 commit comments