diff --git a/src/components/micro-frame-slot/component/web.component.ts b/src/components/micro-frame-slot/component/web.component.ts
index d4e5c9a..f6fb144 100644
--- a/src/components/micro-frame-slot/component/web.component.ts
+++ b/src/components/micro-frame-slot/component/web.component.ts
@@ -1,6 +1,7 @@
import { StreamWritable } from "../../stream-source/component/StreamWritable";
-import { STREAM_SOURCE_MAP_CLIENT } from "../../stream-source/component/StreamSource";
+import StreamSource from "../../stream-source/component/StreamSource";
import getWritableDOM from "writable-dom";
+import { getOrCreateStreamSource } from "../../stream-source/component/helper";
interface Input {
slot: string;
@@ -36,34 +37,38 @@ export = {
};
},
onMount() {
- // Only trigger a new load if this wasn't ssr'd, or the src has changed.
+ this.streamSource = getOrCreateStreamSource(this.input.from);
+ this.handleSrcChange = this.handleSrcChange.bind(this);
+ this.streamSource.onInvalidate(this.handleSrcChange);
this.onUpdate();
},
+ handleSrcChange(src: string) {
+ this.curSrc = src;
+ this.forceUpdate();
+ },
onDestroy() {
this.slot?.end();
+ this.streamSource.offInvalidate(this.handleSrcChange);
},
async onUpdate() {
- if (this.slotId === this.input.slot && this.from === this.input.from)
+ if (
+ this.slotId === this.input.slot &&
+ this.from === this.input.from &&
+ this.prevSrc === this.curSrc
+ )
return;
this.state.loading = true;
this.state.err = undefined;
this.slotId = this.input.slot;
this.from = this.input.from;
+ this.prevSrc = this.curSrc;
let writable: ReturnType | undefined;
let err: Error | undefined;
try {
- const streamSource = STREAM_SOURCE_MAP_CLIENT.get(this.from);
- // In case of micro-frame-sse pure server-side rendered,
- // throw error when the slot trying to connect to the stream
- if (!streamSource)
- throw new Error(
- `micro-frame-sse ${this.from} is not defined or server-side rendered.`
- );
-
- this.slot = streamSource.slot(this.slotId);
+ this.slot = this.streamSource.slot(this.slotId);
if (!this.slot) {
return;
@@ -98,9 +103,14 @@ export = {
el: HTMLDivElement;
slotId: string | undefined;
from: string | undefined;
+ prevSrc: string | undefined;
+ curSrc: string | undefined;
slot: StreamWritable | undefined;
+ streamSource: StreamSource;
onUpdate(): unknown;
onCreate(): unknown;
onMount(): unknown;
onDestroy(): unknown;
+ forceUpdate(): unknown;
+ handleSrcChange(src: string): unknown;
};
diff --git a/src/components/micro-frame-slot/component/web.marko b/src/components/micro-frame-slot/component/web.marko
index fe0aab2..2a0c1cb 100644
--- a/src/components/micro-frame-slot/component/web.marko
+++ b/src/components/micro-frame-slot/component/web.marko
@@ -12,5 +12,5 @@ static function noop() {}
We put the streamed html in a preserved fragment.
This allows Marko to avoid diffing that section.
-->
- $ out.bf("@_", component, !state.err && component.slotId === input.slot && component.from === input.from).ef();
+ $ out.bf("@_", component, !state.err && component.slotId === input.slot && component.from === input.from && component.prevSrc === component.curSrc).ef();
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-invalid-sourcename/renders.expected/loading.0.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-invalid-sourcename/renders.expected/loading.0.html
deleted file mode 100644
index a760d8e..0000000
--- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-invalid-sourcename/renders.expected/loading.0.html
+++ /dev/null
@@ -1,6 +0,0 @@
-
- Host app
-
-
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-invalid-sourcename/renders.expected/loading.1.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-invalid-sourcename/renders.expected/loading.1.html
deleted file mode 100644
index d4da446..0000000
--- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-invalid-sourcename/renders.expected/loading.1.html
+++ /dev/null
@@ -1,11 +0,0 @@
-
- Host app
-
-
-
- Slot_1 Error: micro-frame-sse test_error is not defined or server-side rendered.
-
-
-
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-invalid-sourcename/renders.expected/loading.2.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-invalid-sourcename/renders.expected/loading.2.html
deleted file mode 100644
index 9aa28c6..0000000
--- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-invalid-sourcename/renders.expected/loading.2.html
+++ /dev/null
@@ -1,15 +0,0 @@
-
- Host app
-
-
-
- Slot_1 Error: micro-frame-sse test_error is not defined or server-side rendered.
-
-
-
- test_html for slot_2
-
-
-
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.0.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.0.html
new file mode 100644
index 0000000..0fa1059
--- /dev/null
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.0.html
@@ -0,0 +1,9 @@
+
+ Host app
+
+
+
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.1.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.1.html
new file mode 100644
index 0000000..b3a2eb1
--- /dev/null
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.1.html
@@ -0,0 +1,12 @@
+
+ Host app
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.2.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.2.html
new file mode 100644
index 0000000..5cdcd83
--- /dev/null
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.2.html
@@ -0,0 +1,16 @@
+
+ Host app
+
+
+
+
+
+ test_html for slot_1
+
+
+
+
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.3.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.3.html
new file mode 100644
index 0000000..d1886fa
--- /dev/null
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.3.html
@@ -0,0 +1,20 @@
+
+ Host app
+
+
+
+
+
+ test_html for slot_1
+
+
+
+
+ test_html for slot_2
+
+
+
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.4.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.4.html
new file mode 100644
index 0000000..cf6eac2
--- /dev/null
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/loading.4.html
@@ -0,0 +1,21 @@
+
+ Host app
+
+
+
+
+
+ test_html for slot_1
+
+ next chunk for slot_1
+
+
+
+ test_html for slot_2
+
+
+
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.0.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.0.html
new file mode 100644
index 0000000..b3a2eb1
--- /dev/null
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.0.html
@@ -0,0 +1,12 @@
+
+ Host app
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.1.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.1.html
new file mode 100644
index 0000000..5cdcd83
--- /dev/null
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.1.html
@@ -0,0 +1,16 @@
+
+ Host app
+
+
+
+
+
+ test_html for slot_1
+
+
+
+
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.2.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.2.html
new file mode 100644
index 0000000..d1886fa
--- /dev/null
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.2.html
@@ -0,0 +1,20 @@
+
+ Host app
+
+
+
+
+
+ test_html for slot_1
+
+
+
+
+ test_html for slot_2
+
+
+
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.3.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.3.html
new file mode 100644
index 0000000..9487d38
--- /dev/null
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/csr-then-change-src/renders.expected/step-0.3.html
@@ -0,0 +1,21 @@
+
+ Host app
+
+
+
+
+
+ test_html for slot_1
+
+ after src change
+
+
+
+ test_html for slot_2
+
+
+
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-only/renders.expected/loading.2.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-only/renders.expected/loading.2.html
index c00b3f5..b4ebcac 100644
--- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-only/renders.expected/loading.2.html
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-only/renders.expected/loading.2.html
@@ -29,19 +29,17 @@
-
- test_2_html for slot_1
-
-
\ No newline at end of file
+ style="display:none"
+/>
+
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-only/renders.expected/loading.3.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-only/renders.expected/loading.3.html
index 30cba39..ce474d4 100644
--- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-only/renders.expected/loading.3.html
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-only/renders.expected/loading.3.html
@@ -4,15 +4,11 @@
-
-
+/>
test_html for slot_1
@@ -22,63 +18,20 @@
test_html for slot_2
-
-
-
-
- test_2_html for slot_1
-
- next chunk for slot_1
-
-
-
- test_2_html for slot_2
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-invalid-sourcename/renders.expected/loading.0.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/loading.0.html
similarity index 67%
rename from src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-invalid-sourcename/renders.expected/loading.0.html
rename to src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/loading.0.html
index bc935fa..721429b 100644
--- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-invalid-sourcename/renders.expected/loading.0.html
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/loading.0.html
@@ -1,6 +1,9 @@
Host app
+
-Slot_1 Error: micro-frame-sse test_error is not defined.
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-invalid-sourcename/renders.expected/loading.1.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/loading.1.html
similarity index 63%
rename from src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-invalid-sourcename/renders.expected/loading.1.html
rename to src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/loading.1.html
index c935168..99f8541 100644
--- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-invalid-sourcename/renders.expected/loading.1.html
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/loading.1.html
@@ -1,6 +1,9 @@
Host app
+
-Slot_1 Error: micro-frame-sse test_error is not defined.
- test_html for slot_2
+ test_html for slot_1
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/loading.2.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/loading.2.html
new file mode 100644
index 0000000..808df14
--- /dev/null
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/loading.2.html
@@ -0,0 +1,24 @@
+
+ Host app
+
+
+
+
+
+
+
+ test_html for slot_1
+
+ next chunk for slot_1
+
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-only/renders.expected/loading.4.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/loading.3.html
similarity index 63%
rename from src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-only/renders.expected/loading.4.html
rename to src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/loading.3.html
index 608d35d..4a1b2fd 100644
--- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-only/renders.expected/loading.4.html
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/loading.3.html
@@ -1,14 +1,21 @@
Host app
+
+>
+
+
test_html for slot_1
@@ -18,51 +25,24 @@
test_html for slot_2
-
-
- test_2_html for slot_1
-
- next chunk for slot_1
-
-
-
- test_2_html for slot_2
-
+
-
-
-
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-invalid-sourcename/renders.expected/loading.2.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/loading.4.html
similarity index 60%
rename from src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-invalid-sourcename/renders.expected/loading.2.html
rename to src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/loading.4.html
index 2dd02d4..b884d57 100644
--- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-invalid-sourcename/renders.expected/loading.2.html
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/loading.4.html
@@ -1,36 +1,29 @@
Host app
-
-
+
+
+
+
+ test_html for slot_1
+
+ next chunk for slot_1
-Slot_1 Error: micro-frame-sse test_error is not defined.
-
+
test_html for slot_2
-
-
+/>
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/step-0.0.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/step-0.0.html
new file mode 100644
index 0000000..d5debbf
--- /dev/null
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/step-0.0.html
@@ -0,0 +1,20 @@
+
+ Host app
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-invalid-sourcename/renders.expected/loading.3.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/step-0.1.html
similarity index 64%
rename from src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-invalid-sourcename/renders.expected/loading.3.html
rename to src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/step-0.1.html
index 80cb268..1217e3f 100644
--- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-invalid-sourcename/renders.expected/loading.3.html
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/step-0.1.html
@@ -1,28 +1,24 @@
Host app
-
-Slot_1 Error: micro-frame-sse test_error is not defined.
-
+
+
+
- test_html for slot_2
+ test_html for slot_1
+
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/step-0.2.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/step-0.2.html
new file mode 100644
index 0000000..a9859be
--- /dev/null
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/step-0.2.html
@@ -0,0 +1,28 @@
+
+ Host app
+
+
+
+
+
+ test_html for slot_1
+
+
+
+
+ test_html for slot_2
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/step-0.3.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/step-0.3.html
new file mode 100644
index 0000000..d13d45b
--- /dev/null
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-csr-change-src/renders.expected/step-0.3.html
@@ -0,0 +1,29 @@
+
+ Host app
+
+
+
+
+
+ test_html for slot_1
+
+ after src change
+
+
+
+ test_html for slot_2
+
+
+
+
+
\ No newline at end of file
diff --git a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-toggle-slot/renders.expected/step-1.0.html b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-toggle-slot/renders.expected/step-1.0.html
index 0ab4a8f..270dd5d 100644
--- a/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-toggle-slot/renders.expected/step-1.0.html
+++ b/src/components/micro-frame-sse/__tests__/__snapshots__/micro-frame-sse/ssr-then-toggle-slot/renders.expected/step-1.0.html
@@ -5,9 +5,7 @@
Toggle
-
- Slot_1 Error: micro-frame-sse test is not defined or server-side rendered.
-