Skip to content

Commit bfbb121

Browse files
committed
[scramjet/core] remove prefix, wisp, codec from global config and move them to new ScramjetContext object
1 parent 36b2f27 commit bfbb121

File tree

10 files changed

+225
-172
lines changed

10 files changed

+225
-172
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ import { createLocationProxy } from "@client/location";
66
import { createWrapFn } from "@client/shared/wrap";
77
import { NavigateEvent } from "@client/events";
88
import { rewriteUrl, unrewriteUrl, type URLMeta } from "@rewriters/url";
9-
import { bareTransport, config, flagEnabled } from "@/shared";
9+
import {
10+
bareTransport,
11+
ClientRPCDefs,
12+
config,
13+
flagEnabled,
14+
ScramjetContext,
15+
ScramjetInterface,
16+
} from "@/shared";
1017
import { CookieJar } from "@/shared/cookie";
1118
import { iswindow } from "./entry";
1219
import { SingletonBox } from "./singletonbox";
@@ -100,6 +107,8 @@ export class ScramjetClient {
100107
locationProxy: any;
101108
serviceWorker: ServiceWorkerContainer;
102109
bare: BareClient;
110+
context: ScramjetContext;
111+
rpc: ClientRPCDefs;
103112

104113
natives: NativeStore;
105114
descriptors: DescriptorStore;
@@ -356,7 +365,6 @@ export class ScramjetClient {
356365
return frame.name;
357366
}
358367
},
359-
prefix: new URL(location.origin + config.prefix),
360368
};
361369
this.locationProxy = createLocationProxy(this, global);
362370

@@ -437,7 +445,7 @@ export class ScramjetClient {
437445
}
438446

439447
get url(): URL {
440-
return new URL(unrewriteUrl(this.global.location.href, this.meta));
448+
return new URL(unrewriteUrl(this.global.location.href, this.context));
441449
}
442450

443451
set url(url: URL | string) {
@@ -449,7 +457,7 @@ export class ScramjetClient {
449457
}
450458
if (ev.defaultPrevented) return;
451459

452-
this.global.location.href = rewriteUrl(ev.url, this.meta);
460+
this.global.location.href = rewriteUrl(ev.url, this.context, this.meta);
453461
}
454462

455463
// below are the utilities for proxying and trapping dom APIs
@@ -547,10 +555,11 @@ export class ScramjetClient {
547555

548556
const pst = Error.prepareStackTrace;
549557

558+
let client = this;
550559
Error.prepareStackTrace = function (err, s) {
551560
if (
552561
s[0].getFileName() &&
553-
!s[0].getFileName().startsWith(location.origin + config.prefix)
562+
!s[0].getFileName().startsWith(client.context.prefix.href)
554563
) {
555564
return { stack: err.stack };
556565
}

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// entrypoint for scramjet.client.js
22

33
import {
4-
loadCodecs,
4+
ClientRPCDefs,
5+
ScramjetContext,
56
ScramjetInterface,
67
setBareTransport,
78
setConfig,
8-
setInterface,
99
} from "@/shared/index";
1010
import { SCRAMJETCLIENT } from "@/symbols";
1111
import { ScramjetClient } from "@client/index";
@@ -28,21 +28,23 @@ function createFrameId() {
2828

2929
export type ScramjetClientEntryInit = {
3030
config: ScramjetConfig;
31-
interface: ScramjetInterface;
31+
context: ScramjetContext;
32+
rpc: ClientRPCDefs;
3233
transport: BareTransport;
3334
cookies: string;
3435
};
36+
3537
export function loadAndHook(init: ScramjetClientEntryInit) {
3638
setConfig(init.config);
37-
setInterface(init.interface);
3839
setBareTransport(init.transport);
3940

4041
dbg.log("initializing scramjet client");
4142
// if it already exists, that means the handlers have probably already been setup by the parent document
4243
if (!(SCRAMJETCLIENT in <Partial<typeof self>>globalThis)) {
43-
loadCodecs();
44-
4544
const client = new ScramjetClient(globalThis);
45+
client.context = init.context;
46+
client.rpc = init.rpc;
47+
4648
const frame: HTMLIFrameElement =
4749
globalThis.frameElement as HTMLIFrameElement;
4850
if (frame && !frame.name) {

0 commit comments

Comments
 (0)