Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Sep 11, 2024
1 parent e68acd5 commit 122e512
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
23 changes: 13 additions & 10 deletions packages/react-server/src/entry/ssr.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createDebug, tinyassert } from "@hiogawa/utils";
import { createMemoryHistory } from "@tanstack/history";
import ReactDOMServer from "react-dom/server.edge";
import type { ModuleNode, ViteDevServer } from "vite";
import type { DevEnvironment, EnvironmentModuleNode } from "vite";
import type { SsrAssetsType } from "../features/assets/plugin";
import { DEV_SSR_CSS, SERVER_CSS_PROXY } from "../features/assets/shared";
import {
Expand Down Expand Up @@ -265,21 +265,24 @@ async function devInspectHandler(request: Request) {
tinyassert(request.method === "POST");
const data = await request.json();
if (data.type === "module") {
let mod: ModuleNode | undefined;
let mod: EnvironmentModuleNode | undefined;
if (data.environment === "ssr") {
mod = await getModuleNode($__global.dev.server, data.url, true);
mod = await getModuleNode(
$__global.dev.server.environments.ssr,
data.url,
);
}
if (data.environment === "react-server") {
// mod = await getModuleNode($__global.dev.reactServer, data.url, true);
mod = await getModuleNode(
$__global.dev.server.environments["react-server"]!,
data.url,
);
}
const result = mod && {
id: mod.id,
lastInvalidationTimestamp: mod.lastInvalidationTimestamp,
importers: [...(mod.importers ?? [])].map((m) => m.id),
ssrImportedModules: [...(mod.ssrImportedModules ?? [])].map((m) => m.id),
clientImportedModules: [...(mod.clientImportedModules ?? [])].map(
(m) => m.id,
),
importedModules: [...(mod.importedModules ?? [])].map((m) => m.id),
};
return new Response(JSON.stringify(result || false, null, 2), {
headers: { "content-type": "application/json" },
Expand All @@ -288,8 +291,8 @@ async function devInspectHandler(request: Request) {
tinyassert(false);
}

async function getModuleNode(server: ViteDevServer, url: string, ssr: boolean) {
const resolved = await server.moduleGraph.resolveUrl(url, ssr);
async function getModuleNode(server: DevEnvironment, url: string) {
const resolved = await server.moduleGraph.resolveUrl(url);
return server.moduleGraph.getModuleById(resolved[1]);
}

Expand Down
1 change: 0 additions & 1 deletion packages/react-server/src/features/assets/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export async function collectStyleUrls(
server: DevEnvironment,
{ entries }: { entries: string[] },
) {
// const visited = new Set<string>();
const visited = new Set<EnvironmentModuleNode>();

async function traverse(url: string) {
Expand Down
1 change: 0 additions & 1 deletion packages/react-server/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type { CallServerCallback } from "./types/react";
export const $__global: {
dev: {
server: ViteDevServer;
// reactServer: ViteDevServer;
reactServerRunner: ModuleRunner;
manager: PluginStateManager;
};
Expand Down

0 comments on commit 122e512

Please sign in to comment.