Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 77ebb85

Browse files
committed
Clean up
1 parent feedb15 commit 77ebb85

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

server/build.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function build(serverEntry?: string) {
5151
return [filename, exportNames];
5252
}));
5353
}
54-
const port = Deno.env.get("ALEPH_MODULES_PROXY_PORT");
54+
const modulesProxyPort = Deno.env.get("ALEPH_MODULES_PROXY_PORT");
5555
const serverEntryCode = [
5656
`import { DependencyGraph } from "${alephPkgUri}/server/graph.ts";`,
5757
`import graph from "./server_dependency_graph.js";`,
@@ -86,7 +86,7 @@ export async function build(serverEntry?: string) {
8686
if (!hasDefaultExport && !hasDataExport) {
8787
return [];
8888
}
89-
const url = `http://localhost:${port}${filename.slice(1)}`;
89+
const url = `http://localhost:${modulesProxyPort}${filename.slice(1)}`;
9090
return [
9191
`import { ${
9292
[
@@ -102,7 +102,7 @@ export async function build(serverEntry?: string) {
102102
} });`,
103103
];
104104
}),
105-
serverEntry && `import "http://localhost:${port}/${basename(serverEntry)}";`,
105+
serverEntry && `import "http://localhost:${modulesProxyPort}/${basename(serverEntry)}";`,
106106
!serverEntry && `import { serve } from "${alephPkgUri}/server/mode.ts";`,
107107
!serverEntry && `serve();`,
108108
].flat().filter(Boolean).join("\n");
@@ -125,15 +125,15 @@ export async function build(serverEntry?: string) {
125125
);
126126
}
127127

128-
const forceBundle = (importUrl: string) => {
128+
const shouldBundle = (importUrl: string) => {
129129
return importUrl === alephPkgUri + "/server/mod.ts" ||
130130
importUrl === alephPkgUri + "/server/transformer.ts" ||
131131
// since deno deploy doesn't support importMap, we need to resolve the 'react' import
132132
importUrl.startsWith(alephPkgUri + "/framework/react/") ||
133-
importUrl.startsWith(`http://localhost:${Deno.env.get("ALEPH_MODULES_PROXY_PORT")}/`);
133+
importUrl.startsWith(`http://localhost:${modulesProxyPort}/`);
134134
};
135135

136-
// build server entry
136+
// build the server entry
137137
await esbuild({
138138
stdin: {
139139
contents: serverEntryCode,
@@ -144,7 +144,7 @@ export async function build(serverEntry?: string) {
144144
format: "esm",
145145
target: ["esnext"],
146146
bundle: true,
147-
minify: !Deno.env.get("ALEPH_DEV_PORT"),
147+
minify: !Deno.env.get("ALEPH_DEV"),
148148
treeShaking: true,
149149
sourcemap: true,
150150
jsxFactory: jsxCofig.jsxRuntime === "preact" ? "h" : "React.createElement",
@@ -156,6 +156,7 @@ export async function build(serverEntry?: string) {
156156
build.onResolve({ filter: /.*/ }, (args) => {
157157
let importUrl = args.path;
158158
if (importUrl in importMap.imports) {
159+
// since deno deploy doesn't support importMap, we need to resolve the 'react' import
159160
importUrl = importMap.imports[importUrl];
160161
}
161162

@@ -168,13 +169,13 @@ export async function build(serverEntry?: string) {
168169

169170
if (args.namespace === "http") {
170171
const { href } = new URL(path, args.importer);
171-
if (!forceBundle(href)) {
172+
if (!shouldBundle(href)) {
172173
return { path: href, external: true };
173174
}
174175
return { path: href, namespace: "http" };
175176
}
176177

177-
if (isRemote && forceBundle(path)) {
178+
if (isRemote && shouldBundle(path)) {
178179
return { path, namespace: "http" };
179180
}
180181

@@ -258,6 +259,7 @@ export async function build(serverEntry?: string) {
258259
while (tasks.length > 0) {
259260
const deps = new Set<string>();
260261
await Promise.all(tasks.map(async (specifier) => {
262+
clientModules.add(specifier);
261263
const url = new URL(util.isLikelyHttpURL(specifier) ? toLocalPath(specifier) : specifier, "http://localhost");
262264
const isCSS = url.pathname.endsWith(".css");
263265
const req = new Request(url.toString());
@@ -273,7 +275,6 @@ export async function build(serverEntry?: string) {
273275
Deno.open(savePath, { write: true, create: true }),
274276
]);
275277
await res.body?.pipeTo(file.writable);
276-
clientModules.add(specifier);
277278
if (!isCSS) {
278279
const clientDependencyGraph: DependencyGraph | undefined = Reflect.get(globalThis, "clientDependencyGraph");
279280
clientDependencyGraph?.get(specifier)?.deps?.forEach(({ specifier }) => {

server/renderer.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export type SSRContext = {
1313
readonly url: URL;
1414
readonly routeModules: RouteModule[];
1515
readonly headCollection: string[];
16-
readonly errorBoundaryHandler?: CallableFunction;
1716
readonly suspense: boolean;
17+
readonly errorBoundaryHandler?: CallableFunction;
1818
readonly signal: AbortSignal;
1919
readonly bootstrapScripts?: string[];
2020
};
@@ -32,23 +32,23 @@ export type SSR = {
3232
render(ssr: SSRContext): Promise<string | ReadableStream> | string | ReadableStream;
3333
} | ((ssr: SSRContext) => Promise<string | ReadableStream> | string | ReadableStream);
3434

35+
type SSRResult = {
36+
context: SSRContext;
37+
errorBoundaryHandlerFilename?: string;
38+
body: ReadableStream | string;
39+
suspenseData: Record<string, unknown>;
40+
};
41+
3542
export type RenderOptions = {
36-
indexHtml: Uint8Array;
3743
routes: Routes;
44+
indexHtml: Uint8Array;
3845
customHTMLRewriter: Map<string, HTMLRewriterHandlers>;
3946
isDev: boolean;
4047
ssr?: SSR;
4148
};
4249

43-
type SSRResult = {
44-
context: SSRContext;
45-
errorBoundaryHandlerFilename?: string;
46-
body: string | ReadableStream;
47-
suspenseData: Record<string, unknown>;
48-
};
49-
5050
/** The virtual `bootstrapScript` to mark the ssr streaming initial UI is ready */
51-
const bootstrapScript = `data:text/javascript;charset=utf-8;base64,${btoa("/* hydrate bootstrap */")}`;
51+
const bootstrapScript = `data:text/javascript;charset=utf-8;base64,${btoa("/* stage ready */")}`;
5252

5353
export default {
5454
async fetch(req: Request, ctx: Record<string, unknown>, options: RenderOptions): Promise<Response> {
@@ -68,7 +68,7 @@ export default {
6868
headCollection,
6969
suspense,
7070
signal: req.signal,
71-
bootstrapScripts: suspense ? [bootstrapScript] : undefined,
71+
bootstrapScripts: [bootstrapScript],
7272
};
7373
const body = await render(ssrContext);
7474
const serverDependencyGraph: DependencyGraph | undefined = Reflect.get(globalThis, "serverDependencyGraph");
@@ -421,21 +421,21 @@ const errorHtml = (message: string) => `
421421
background-color: rgba(255, 0, 0, 0.1);
422422
color: rgba(255, 0, 0, 1);
423423
}
424-
.error pre {
425-
position: relative;
426-
line-height: 1.4;
427-
}
428-
.error code {
429-
font-size: 14px;
430-
}
431-
.logo {
424+
.error .logo {
432425
position: absolute;
433426
top: 50%;
434427
left: 50%;
435428
margin-top: -45px;
436429
margin-left: -45px;
437430
opacity: 0.1;
438431
}
432+
.error pre {
433+
position: relative;
434+
line-height: 1.4;
435+
}
436+
.error code {
437+
font-size: 14px;
438+
}
439439
</style>
440440
</head>
441441
<body>

0 commit comments

Comments
 (0)