fix: tailwind failing on non-existant files (#2118)
This commit is contained in:
+8
-2
@@ -82,8 +82,8 @@ export default function tailwind(): Plugin {
|
|||||||
const tailwindMiddleware: PluginMiddleware = {
|
const tailwindMiddleware: PluginMiddleware = {
|
||||||
path: "/",
|
path: "/",
|
||||||
middleware: {
|
middleware: {
|
||||||
handler: async (req, ctx) => {
|
handler: async (_req, ctx) => {
|
||||||
const pathname = new URL(req.url).pathname;
|
const pathname = ctx.url.pathname;
|
||||||
|
|
||||||
if (pathname.endsWith(".css.map")) {
|
if (pathname.endsWith(".css.map")) {
|
||||||
const cached = cache.get(pathname);
|
const cached = cache.get(pathname);
|
||||||
@@ -110,6 +110,12 @@ export default function tailwind(): Plugin {
|
|||||||
};
|
};
|
||||||
cache.set(pathname, cached);
|
cache.set(pathname, cached);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// If the file is not found than it's likely a virtual file
|
||||||
|
// by the user that they respond to via a middleware.
|
||||||
|
if (err instanceof Deno.errors.NotFound) {
|
||||||
|
return ctx.next();
|
||||||
|
}
|
||||||
|
|
||||||
cached = {
|
cached = {
|
||||||
content: text,
|
content: text,
|
||||||
map: "",
|
map: "",
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ export async function getInternalFreshState(
|
|||||||
return {
|
return {
|
||||||
config: internalConfig,
|
config: internalConfig,
|
||||||
manifest,
|
manifest,
|
||||||
loadSnapshot: !isLegacyDev,
|
loadSnapshot: !isLegacyDev && !config.dev,
|
||||||
denoJsonPath,
|
denoJsonPath,
|
||||||
denoJson,
|
denoJson,
|
||||||
build: false,
|
build: false,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// This file is automatically updated during development when running `dev.ts`.
|
// This file is automatically updated during development when running `dev.ts`.
|
||||||
|
|
||||||
import * as $_app from "./routes/_app.tsx";
|
import * as $_app from "./routes/_app.tsx";
|
||||||
|
import * as $_middleware from "./routes/_middleware.ts";
|
||||||
import * as $index from "./routes/index.tsx";
|
import * as $index from "./routes/index.tsx";
|
||||||
|
|
||||||
import { type Manifest } from "$fresh/server.ts";
|
import { type Manifest } from "$fresh/server.ts";
|
||||||
@@ -10,6 +11,7 @@ import { type Manifest } from "$fresh/server.ts";
|
|||||||
const manifest = {
|
const manifest = {
|
||||||
routes: {
|
routes: {
|
||||||
"./routes/_app.tsx": $_app,
|
"./routes/_app.tsx": $_app,
|
||||||
|
"./routes/_middleware.ts": $_middleware,
|
||||||
"./routes/index.tsx": $index,
|
"./routes/index.tsx": $index,
|
||||||
},
|
},
|
||||||
islands: {},
|
islands: {},
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { FreshContext } from "$fresh/server.ts";
|
||||||
|
|
||||||
|
export async function handler(
|
||||||
|
_req: Request,
|
||||||
|
ctx: FreshContext,
|
||||||
|
) {
|
||||||
|
if (ctx.url.pathname === "/middleware-only.css") {
|
||||||
|
return new Response(".foo-bar { color: red }", {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "text/css",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return await ctx.next();
|
||||||
|
}
|
||||||
@@ -37,3 +37,15 @@ Deno.test("TailwindCSS - config", async () => {
|
|||||||
{ loadConfig: true },
|
{ loadConfig: true },
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("TailwindCSS - middleware only css", async () => {
|
||||||
|
await withFakeServe(
|
||||||
|
"./tests/fixture_tailwind/dev.ts",
|
||||||
|
async (server) => {
|
||||||
|
const res = await server.get("/middleware-only.css");
|
||||||
|
const content = await res.text();
|
||||||
|
assertStringIncludes(content, ".foo-bar");
|
||||||
|
},
|
||||||
|
{ loadConfig: true },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user