Skip to content

Commit 50b72d9

Browse files
committed
[scramjet/core] final fixes
1 parent 44dcf15 commit 50b72d9

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

packages/scramjet/packages/core/src/client/client.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ export class ScramjetClient {
108108
locationProxy: any;
109109
serviceWorker: ServiceWorkerContainer;
110110
bare: BareClient;
111-
context: ScramjetContext;
112-
rpc: ClientRPCDefs;
113111

114112
natives: NativeStore;
115113
descriptors: DescriptorStore;
@@ -130,7 +128,11 @@ export class ScramjetClient {
130128

131129
box: SingletonBox;
132130

133-
constructor(public global: typeof globalThis) {
131+
constructor(
132+
public global: typeof globalThis,
133+
public context: ScramjetContext,
134+
public rpc: ClientRPCDefs
135+
) {
134136
if (SCRAMJETCLIENT in global) {
135137
console.error(
136138
"attempted to initialize a scramjet client, but one is already loaded - this is very bad"

packages/scramjet/packages/core/src/client/dom/element.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,11 @@ export default function (client: ScramjetClient, self: typeof window) {
527527
try {
528528
if (!(SCRAMJETCLIENT in realwin)) {
529529
// hook the iframe before the client can start to steal globals out of it
530-
const newclient = new ScramjetClient(realwin);
530+
const newclient = new ScramjetClient(
531+
realwin,
532+
client.context,
533+
client.rpc
534+
);
531535
newclient.hook();
532536
}
533537
} catch {
@@ -556,7 +560,11 @@ export default function (client: ScramjetClient, self: typeof window) {
556560
if (!realwin) return realwin;
557561

558562
if (!(SCRAMJETCLIENT in realwin)) {
559-
const newclient = new ScramjetClient(realwin);
563+
const newclient = new ScramjetClient(
564+
realwin,
565+
client.context,
566+
client.rpc
567+
);
560568
newclient.hook();
561569
}
562570

packages/scramjet/packages/core/src/client/dom/open.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ export default function (client: ScramjetClient) {
1919
if (SCRAMJETCLIENT in realwin) {
2020
return ctx.return(realwin[SCRAMJETCLIENT].global);
2121
} else {
22-
const newclient = new ScramjetClient(realwin);
22+
const newclient = new ScramjetClient(
23+
realwin,
24+
client.context,
25+
client.rpc
26+
);
2327
// hook the opened window
2428
newclient.hook();
2529

packages/scramjet/packages/core/src/client/entry.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ export function loadAndHook(init: ScramjetClientEntryInit) {
4040
dbg.log("initializing scramjet client");
4141
// if it already exists, that means the handlers have probably already been setup by the parent document
4242
if (!(SCRAMJETCLIENT in <Partial<typeof self>>globalThis)) {
43-
const client = new ScramjetClient(globalThis);
44-
client.context = init.context;
45-
client.rpc = init.rpc;
43+
const client = new ScramjetClient(globalThis, init.context, init.rpc);
4644

4745
const frame: HTMLIFrameElement =
4846
globalThis.frameElement as HTMLIFrameElement;

packages/scramjet/packages/core/src/fetch/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ export function parseRequest(
261261
strippedUrl.searchParams.delete(param);
262262
}
263263

264+
if (!URL.canParse(unrewriteUrl(strippedUrl, handler.context))) {
265+
throw new Error(`unable to parse rewritten url: ${strippedUrl.href}`);
266+
}
264267
const url = new URL(unrewriteUrl(strippedUrl, handler.context));
265268

266269
if (url.origin === new URL(request.rawUrl).origin) {

0 commit comments

Comments
 (0)