Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions packages/start/src/config/fs-routes/fs-watcher.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import type {
EnvironmentModuleNode,
FSWatcher,
PluginOption,
ViteDevServer,
} from "vite";
import type { EnvironmentModuleNode, FSWatcher, PluginOption, ViteDevServer } from "vite";
import { VITE_ENVIRONMENTS } from "../constants.ts";
import { moduleId } from "./index.ts";
import type { BaseFileSystemRouter } from "./router.ts";
Expand Down Expand Up @@ -31,21 +26,31 @@ function createRoutesReloader(
return () => routes.removeEventListener("reload", handleRoutesReload);

function handleRoutesReload(): void {
const envName =
environment === "ssr" ? VITE_ENVIRONMENTS.server : VITE_ENVIRONMENTS.client;
const envName = environment === "ssr" ? VITE_ENVIRONMENTS.server : VITE_ENVIRONMENTS.client;
const devEnv = server.environments[envName];
if (!devEnv?.moduleGraph) return;

const mod: EnvironmentModuleNode | undefined =
devEnv.moduleGraph.getModuleById(moduleId);
const mod: EnvironmentModuleNode | undefined = devEnv.moduleGraph.getModuleById(moduleId);
if (mod) {
const seen = new Set<EnvironmentModuleNode>();
devEnv.moduleGraph.invalidateModule(mod, seen);
}

if (environment !== "ssr") {
if (mod) {
devEnv.reloadModule(mod);

const extensions = [".css", ".scss", ".sass.", ".less"];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a requirement, but we could probably use a RegExp here (/\.(c|sc|sa|le)ss$/i)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lxsmnsyc I think we can close this PR 😅, its superseded by #2171

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I believe it solves both problems lol

for (const [file, mods] of devEnv.moduleGraph.fileToModulesMap) {
if (extensions.some(ext => file.endsWith(ext))) {
for (const cssModule of mods) {
if (cssModule) {
devEnv.reloadModule(cssModule);
}
}
}
}

} else if (devEnv.hot) {
devEnv.hot.send({ type: "full-reload" });
}
Expand Down
Loading