Skip to content

Commit

Permalink
fix: check for out.global.req/request when looking for incomingMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
bill-min authored and DylanPiercey committed Nov 29, 2022
1 parent 385f054 commit d469c64
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
Host app
</div>
<noscript
id="GENERATED-0"
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div>
Host app
</div>
<noscript
id="GENERATED-0"
/>
<div
id="GENERATED-1"
style="display:none"
/>
<div
id="GENERATED-2"
style="display:none"
>
<div
data-src="embed"
id="GENERATED-3"
>
<noscript
id="GENERATED-4"
/>
</div>
<div
data-from="test"
data-slot="slot_1"
id="GENERATED-5"
>
Could not get request from stream/global. Please assign out.global.req with proper request object.
</div>
<div
data-from="test"
data-slot="slot_2"
id="GENERATED-6"
/>
</div>
<script>
function $af(d,a,e,l,g,h,k,b,f,c){c=$af;if(a&&!c[a])(c[a+="$"]||(c[a]=[])).push(d);else{e=document;l=e.getElementById("af"+d);g=e.getElementById("afph"+d);h=e.createDocumentFragment();k=l.childNodes;b=0;for(f=k.length;b&lt;f;b++)h.appendChild(k.item(0));g&&g.parentNode.replaceChild(h,g);c[d]=1;if(a=c[d+"$"])for(b=0,f=a.length;b&lt;f;b++)c(a[b])}};$af(1);$af(0)
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div>
Host app
</div>
<div
data-src="embed"
id="GENERATED-0"
/>
<div
data-from="test"
data-slot="slot_1"
id="GENERATED-1"
>
Could not get request from stream/global. Please assign out.global.req with proper request object.
</div>
<div
data-from="test"
data-slot="slot_2"
id="GENERATED-2"
/>
<div
id="GENERATED-3"
style="display:none"
/>
<div
id="GENERATED-4"
style="display:none"
/>
<script>
function $af(d,a,e,l,g,h,k,b,f,c){c=$af;if(a&&!c[a])(c[a+="$"]||(c[a]=[])).push(d);else{e=document;l=e.getElementById("af"+d);g=e.getElementById("afph"+d);h=e.createDocumentFragment();k=l.childNodes;b=0;for(f=k.length;b&lt;f;b++)h.appendChild(k.item(0));g&&g.parentNode.replaceChild(h,g);c[d]=1;if(a=c[d+"$"])for(b=0,f=a.length;b&lt;f;b++)c(a[b])}};$af(1);$af(0)
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { wait } from "../../../../../__tests__/queue";
import fs from "fs";
import path from "path";

$ const slot_1_html = fs.readFileSync(path.resolve(__dirname ,'slot_1.html'), 'utf8');
$ const slot_2_html = fs.readFileSync(path.resolve(__dirname ,'slot_2.html'), 'utf8');
$ const first = `id: slot_1\ndata: ${slot_1_html.replace(/\r?\n/g, '')}\n\n`;
$ const second = `id: slot_2\ndata: ${slot_2_html.replace(/\r?\n/g, '')}\n\n`;
$ const third = `id: slot_1\ntype: update\ndata: next chunk for slot_1`;

<await(wait())>
<@then>
$!{first}
<await(wait())>
<@then>
$!{second}
<await(wait())>
<@then>
$!{third}
</@then>
</await>
</@then>
</await>
</@then>
</await>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Example</title>
<esbuild-assets/>
</head>
<body>
<div>Host app</div>
<await(new Promise((res) => setTimeout(res))) client-reorder>
<@then>
<micro-frame-sse
src="embed"
name="test"
read=((e) => [e.lastEventId, e.data])
/>
<micro-frame-slot from="test" slot="slot_1">
<@catch|err|>${err.message}</@catch>
</micro-frame-slot>
<micro-frame-slot from="test" slot="slot_2"/>
</@then>
</await>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>test_html for slot_1</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>test_html for slot_2</p>
5 changes: 5 additions & 0 deletions src/components/micro-frame-sse/__tests__/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,9 @@ describe("micro-frame-sse", () => {
"ssr timeout",
fixture(path.join(__dirname, "fixtures/ssr-timeout"))
);

describe(
"ssr behind reorder",
fixture(path.join(__dirname, "fixtures/ssr-behind-reorder"))
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
Host app
</div>
<noscript
id="GENERATED-0"
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div>
Host app
</div>
<noscript
id="GENERATED-0"
/>
<div
id="GENERATED-1"
style="display:none"
>
<div
data-src="embed"
id="GENERATED-2"
>
Could not get request from stream/global. Please assign out.global.req with proper request object.
</div>
</div>
<script>
function $af(d,a,e,l,g,h,k,b,f,c){c=$af;if(a&&!c[a])(c[a+="$"]||(c[a]=[])).push(d);else{e=document;l=e.getElementById("af"+d);g=e.getElementById("afph"+d);h=e.createDocumentFragment();k=l.childNodes;b=0;for(f=k.length;b&lt;f;b++)h.appendChild(k.item(0));g&&g.parentNode.replaceChild(h,g);c[d]=1;if(a=c[d+"$"])for(b=0,f=a.length;b&lt;f;b++)c(a[b])}};$af(0)
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div>
Host app
</div>
<div
data-src="embed"
id="GENERATED-0"
>
Could not get request from stream/global. Please assign out.global.req with proper request object.
</div>
<div
id="GENERATED-1"
style="display:none"
/>
<script>
function $af(d,a,e,l,g,h,k,b,f,c){c=$af;if(a&&!c[a])(c[a+="$"]||(c[a]=[])).push(d);else{e=document;l=e.getElementById("af"+d);g=e.getElementById("afph"+d);h=e.createDocumentFragment();k=l.childNodes;b=0;for(f=k.length;b&lt;f;b++)h.appendChild(k.item(0));g&&g.parentNode.replaceChild(h,g);c[d]=1;if(a=c[d+"$"])for(b=0,f=a.length;b&lt;f;b++)c(a[b])}};$af(0)
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<esbuild-assets/>
<div>
Embedded App.
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Example</title>
<esbuild-assets/>
</head>
<body>
<div>Host app</div>
<await(new Promise((res) => setTimeout(res))) client-reorder>
<@then>
<micro-frame src="embed">
<@catch|err|>${err.message}</@catch>
</micro-frame>
</@then>
</await>
</body>
</html>
5 changes: 5 additions & 0 deletions src/components/micro-frame/__tests__/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,8 @@ describe(
"ssr custom fetch",
fixture(path.join(__dirname, "fixtures/ssr-custom-fetch"))
);

describe(
"ssr behind reorder",
fixture(path.join(__dirname, "fixtures/ssr-behind-reorder"))
);
4 changes: 2 additions & 2 deletions src/components/micro-frame/component/node.marko
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ static const cachePath = path.resolve("node_modules/.cache/fetch");
static const strictSSL = process.env.NODE_TLS_REJECT_UNAUTHORIZED !== "0";

static async function fetchStream(input, out) {
const incomingMessage = out.stream && (out.stream.req || out.stream.request);
const incomingMessage = out.stream && (out.stream.req || out.stream.request) || out.global.req || out.global.request;
if (!incomingMessage) {
throw new Error("Could not get request from stream.");
throw new Error("Could not get request from stream/global. Please assign out.global.req with proper request object.");
}
const url = new URL(input.src, `${incomingMessage.protocol}://${incomingMessage.headers.host}`);
Expand Down
4 changes: 2 additions & 2 deletions src/components/stream-source/component/node.marko
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import StreamSource, { STREAM_SOURCE_MAP } from "./StreamSource";
static const cachePath = path.resolve("node_modules/.cache/fetch");

$ const request = async () => {
const incomingMessage = out.stream && (out.stream.req || out.stream.request);
const incomingMessage = out.stream && (out.stream.req || out.stream.request) || out.global.req || out.global.request;
if (!incomingMessage) {
throw new Error("Could not get request from stream.");
throw new Error("Could not get request from stream/global. Please assign out.global.req with proper request object.");
}
const url = new URL(input.src, `${incomingMessage.protocol}://${incomingMessage.headers.host}`);
Expand Down

0 comments on commit d469c64

Please sign in to comment.