Skip to content

Commit 1480897

Browse files
committed
fix(repl): store update issues
1 parent 0d726c0 commit 1480897

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

packages/docs/src/repl/ui/repl-output-symbols.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ export const ReplOutputSymbols = component$(({ outputs }: ReplOutputSymbolsProps
99
selectedPath.value = path;
1010
});
1111

12+
const segments = outputs.filter((o) => !!o.segment);
13+
1214
return (
1315
<div class="output-result output-modules">
1416
<div class="file-tree">
1517
<div class="file-tree-header">Symbols</div>
1618
<div class="file-tree-items">
17-
{outputs.map((o, i) => (
19+
{segments.map((o, i) => (
1820
<div key={o.path}>
1921
<a
2022
href="#"
@@ -36,23 +38,21 @@ export const ReplOutputSymbols = component$(({ outputs }: ReplOutputSymbolsProps
3638
</div>
3739
</div>
3840
<div class="file-modules" id={FILE_MODULE_DIV_ID}>
39-
{outputs
40-
.filter((o) => !!o.segment)
41-
.map((o, i) => (
42-
<div class="file-item" data-symbol-item={i} key={o.path}>
43-
<div class="file-info">
44-
<span>{o.segment?.canonicalFilename}</span>
45-
</div>
46-
<div class="file-text">
47-
<CodeBlock
48-
pathInView$={pathInView$}
49-
path={o.path}
50-
code={o.code}
51-
observerRootId={FILE_MODULE_DIV_ID}
52-
/>
53-
</div>
41+
{segments.map((o, i) => (
42+
<div class="file-item" data-symbol-item={i} key={o.path}>
43+
<div class="file-info">
44+
<span>{o.segment?.canonicalFilename}</span>
5445
</div>
55-
))}
46+
<div class="file-text">
47+
<CodeBlock
48+
pathInView$={pathInView$}
49+
path={o.path}
50+
code={o.code}
51+
observerRootId={FILE_MODULE_DIV_ID}
52+
/>
53+
</div>
54+
</div>
55+
))}
5656
</div>
5757
</div>
5858
);

packages/docs/src/repl/ui/repl-output-update.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1+
import { unwrapStore } from '@builder.io/qwik';
12
import type { ReplResult, ReplStore } from '../types';
23

3-
// TODO fix useStore to recursively notify subscribers
4+
// Maybe we should change useStore to recursively notify subscribers when a top-level property changes
45
const deepUpdate = (prev: any, next: any) => {
56
for (const key in next) {
67
if (prev[key] && typeof next[key] === 'object' && typeof prev[key] === 'object') {
78
deepUpdate(prev[key], next[key]);
89
} else {
9-
if (prev[key] !== next[key]) {
10+
if (unwrapStore(prev[key]) !== next[key]) {
1011
prev[key] = next[key];
1112
}
1213
}
1314
}
1415
if (Array.isArray(prev)) {
15-
for (const item of prev) {
16-
if (!next.includes(item)) {
17-
prev.splice(prev.indexOf(item), 1);
18-
}
16+
if (prev.length !== next.length) {
17+
prev.length = next.length;
1918
}
2019
} else {
2120
for (const key in prev) {
@@ -28,14 +27,6 @@ const deepUpdate = (prev: any, next: any) => {
2827

2928
export const updateReplOutput = async (store: ReplStore, result: ReplResult) => {
3029
deepUpdate(store.diagnostics, result.diagnostics);
31-
32-
if (result.diagnostics.length === 0) {
33-
if (result.html && store.html !== result.html) {
34-
store.html = result.html;
35-
store.reload++;
36-
}
37-
}
38-
3930
deepUpdate(store.transformedModules, result.transformedModules);
4031
deepUpdate(store.clientBundles, result.clientBundles);
4132
deepUpdate(store.ssrModules, result.ssrModules);
@@ -47,6 +38,13 @@ export const updateReplOutput = async (store: ReplStore, result: ReplResult) =>
4738
store.events = result.events;
4839
}
4940

41+
if (result.diagnostics.length === 0) {
42+
if (result.html && store.html !== result.html) {
43+
store.html = result.html;
44+
store.reload++;
45+
}
46+
}
47+
5048
if (store.selectedOutputPanel === 'diagnostics' && store.monacoDiagnostics.length === 0) {
5149
store.selectedOutputPanel = 'app';
5250
}

0 commit comments

Comments
 (0)