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

Commit 43d7ab1

Browse files
committed
Clean up
1 parent 9a610fa commit 43d7ab1

File tree

13 files changed

+44
-47
lines changed

13 files changed

+44
-47
lines changed

framework/core/redirect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isFilledString } from "../../shared/util.ts";
22
import events from "./events.ts";
3-
import { matchRoutes, type Router } from "./routes.ts";
3+
import { matchRoutes, type Router } from "./router.ts";
44

55
let router: Router | null = null;
66
let preRedirect: URL | null = null;
Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -148,38 +148,6 @@ export function loadRouterFromTag(): Router {
148148
return { routes: [], prefix: "" };
149149
}
150150

151-
// fetch route data
152-
export async function fetchRouteData(dataCache: Map<string, RouteData>, dataUrl: string, defer?: boolean) {
153-
const rd: RouteData = {};
154-
const fetchData = async () => {
155-
const res = await fetch(dataUrl + (dataUrl.includes("?") ? "&" : "?") + "_data_");
156-
if (!res.ok) {
157-
const err = await FetchError.fromResponse(res);
158-
const details = err.details as { redirect?: { location: string } };
159-
if (err.status === 501 && typeof details.redirect?.location === "string") {
160-
location.href = details.redirect?.location;
161-
return;
162-
}
163-
return err;
164-
}
165-
try {
166-
const data = await res.json();
167-
const cc = res.headers.get("Cache-Control");
168-
rd.dataCacheTtl = cc?.includes("max-age=") ? parseInt(cc.split("max-age=")[1]) : undefined;
169-
rd.dataExpires = Date.now() + (rd.dataCacheTtl || 1) * 1000;
170-
return data;
171-
} catch (_e) {
172-
return new Error("Data must be valid JSON");
173-
}
174-
};
175-
if (defer) {
176-
rd.data = fetchData;
177-
} else {
178-
rd.data = await fetchData();
179-
}
180-
dataCache.set(dataUrl, rd);
181-
}
182-
183151
export function loadSSRModulesFromTag(): RouteModule[] {
184152
const { getRouteModule } = Reflect.get(window, "__aleph");
185153
const el = window.document.getElementById("ssr-data");
@@ -224,6 +192,37 @@ export function loadSSRModulesFromTag(): RouteModule[] {
224192
return [];
225193
}
226194

195+
export async function fetchRouteData(dataCache: Map<string, RouteData>, dataUrl: string, defer?: boolean) {
196+
const rd: RouteData = {};
197+
const fetchData = async () => {
198+
const res = await fetch(dataUrl + (dataUrl.includes("?") ? "&" : "?") + "_data_");
199+
if (!res.ok) {
200+
const err = await FetchError.fromResponse(res);
201+
const details = err.details as { redirect?: { location: string } };
202+
if (err.status === 501 && typeof details.redirect?.location === "string") {
203+
location.href = details.redirect?.location;
204+
return;
205+
}
206+
return err;
207+
}
208+
try {
209+
const data = await res.json();
210+
const cc = res.headers.get("Cache-Control");
211+
rd.dataCacheTtl = cc?.includes("max-age=") ? parseInt(cc.split("max-age=")[1]) : undefined;
212+
rd.dataExpires = Date.now() + (rd.dataCacheTtl || 1) * 1000;
213+
return data;
214+
} catch (_e) {
215+
return new Error("Data must be valid JSON");
216+
}
217+
};
218+
if (defer) {
219+
rd.data = fetchData;
220+
} else {
221+
rd.data = await fetchData();
222+
}
223+
dataCache.set(dataUrl, rd);
224+
}
225+
227226
export function listenHistory(onpopstate: (e: { type: string; url?: URL }) => Promise<void>): () => void {
228227
// deno-lint-ignore no-explicit-any
229228
const navigation = (window as any).navigation;

framework/core/style.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export function applyCSS(url: string, css: string) {
88
el.hasAttribute("ssr")
99
);
1010
if (ssrEl) {
11-
// apply the css at next time
1211
ssrEl.removeAttribute("ssr");
1312
} else {
1413
const prevEls = Array.from(document.head.children).filter((el: Element) => {
@@ -127,7 +126,6 @@ function fixCSSText(cssText: string): string {
127126
function createCSSStyleSheet(css: string): CSSStyleSheet | null {
128127
try {
129128
const sheet = new CSSStyleSheet();
130-
// @ts-ignore
131129
sheet.replaceSync(css);
132130
return sheet;
133131
} catch (_e) {

framework/react/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { FC, ReactNode } from "react";
22
import { createElement, isValidElement, StrictMode, Suspense, useContext, useEffect, useMemo, useState } from "react";
33
import { redirect } from "../core/redirect.ts";
4-
import { RouteModule, watchRouter } from "../core/routes.ts";
5-
import { fetchRouteData, loadSSRModulesFromTag } from "../core/routes.ts";
4+
import { RouteModule, watchRouter } from "../core/router.ts";
5+
import { fetchRouteData, loadSSRModulesFromTag } from "../core/router.ts";
66
import { ForwardPropsContext, RouterContext, type RouterContextProps } from "./context.ts";
77
import { DataProvider, type RouteData } from "./data.ts";
88
import { Err, ErrorBoundary } from "./error.ts";

framework/vue/router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Component, Ref, ShallowRef } from "vue";
22
import { createSSRApp, defineComponent, h, ref, shallowRef, watch } from "vue";
3-
import { RouteModule, watchRouter } from "../core/routes.ts";
4-
import { loadSSRModulesFromTag } from "../core/routes.ts";
3+
import { RouteModule, watchRouter } from "../core/router.ts";
4+
import { loadSSRModulesFromTag } from "../core/router.ts";
55
import type { SSRContext } from "../../server/types.ts";
66
import { RouterContext } from "./context.ts";
77
import { Link } from "./link.ts";

plugins/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { colors, esbuild, path } from "../server/deps.ts";
2-
import type { Router } from "../framework/core/routes.ts";
2+
import type { Router } from "../framework/core/router.ts";
33
import depGraph, { DependencyGraph } from "../server/graph.ts";
44
import log from "../server/log.ts";
55
import { getAlephConfig, getAppDir, getImportMap, getJSXConfig } from "../server/helpers.ts";

server/handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { generateErrorHtml, TransformError } from "../framework/core/error.ts";
2-
import type { Router } from "../framework/core/routes.ts";
2+
import type { Router } from "../framework/core/router.ts";
33
import { isPlainObject, trimSuffix } from "../shared/util.ts";
44
import { createContext } from "./context.ts";
55
import { handleHMR } from "./dev.ts";

server/mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Router } from "../framework/core/routes.ts";
1+
import type { Router } from "../framework/core/router.ts";
22
import { isPlainObject } from "../shared/util.ts";
33
import { createContext } from "./context.ts";
44
import { path } from "./deps.ts";

server/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FetchError } from "../framework/core/error.ts";
2-
import { matchRoutes, type RouteModule, type Router } from "../framework/core/routes.ts";
2+
import { matchRoutes, type RouteModule, type Router } from "../framework/core/router.ts";
33
import { cleanPath, isFilledString, isPlainObject, utf8Enc } from "../shared/util.ts";
44
import { HTMLRewriter, path } from "./deps.ts";
55
import depGraph from "./graph.ts";

server/routing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { URLPatternCompat, type URLPatternInput } from "../framework/core/url_pattern.ts";
2-
import type { Route, RouteMatch, RouteMeta, Router, RouteRegExp } from "../framework/core/routes.ts";
2+
import type { Route, RouteMatch, RouteMeta, Router, RouteRegExp } from "../framework/core/router.ts";
33
import {
44
cleanPath,
55
isFilledString,

0 commit comments

Comments
 (0)