Skip to content

Commit

Permalink
fix: match static files in dev based on the pathname to fix HMR (#69)
Browse files Browse the repository at this point in the history
* Upgrade Remix

* Match static files in dev against the pathname

* Add changelog

* chore: update url creation so doubleslashes dont cause an issue #61

Signed-off-by: Logan McAnsh <[email protected]>

---------

Signed-off-by: Logan McAnsh <[email protected]>
Co-authored-by: Logan McAnsh <[email protected]>
  • Loading branch information
philipp-spiess and mcansh authored Feb 24, 2023
1 parent 513a627 commit 394c89c
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-carpets-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mcansh/remix-fastify": minor
---

Match static files in development based on the pathname to fix HMR.
6 changes: 3 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
},
"dependencies": {
"@mcansh/remix-fastify": "workspace:*",
"@remix-run/node": "1.12.0",
"@remix-run/react": "1.12.0",
"@remix-run/node": "1.13.0",
"@remix-run/react": "1.13.0",
"fastify": "^4.12.0",
"isbot": "^3.6.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@remix-run/dev": "1.12.0",
"@remix-run/dev": "1.13.0",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"dotenv": "^16.0.3",
Expand Down
1 change: 0 additions & 1 deletion example/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = {
appDirectory: "app",
assetsBuildDirectory: "public/build",
serverBuildPath: "build/index.js",
publicPath: "/build/",
future: {
unstable_dev: true,
v2_routeConvention: true,
Expand Down
7 changes: 5 additions & 2 deletions packages/remix-fastify/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from "node:path";
import { pathToFileURL } from "node:url";
import { pathToFileURL, URL } from "node:url";
import fastifyStatic from "@fastify/static";
import type { ServerBuild } from "@remix-run/node";
import type { FastifyPluginAsync, FastifyReply } from "fastify";
Expand Down Expand Up @@ -85,9 +85,12 @@ let remixFastify: FastifyPluginAsync<PluginOptions> = async (
rootDir
);

let origin = `${request.protocol}://${request.hostname}`;
let url = new URL(`${origin}${request.url}`);

let staticFile = staticFiles.find((file) => {
return (
request.url ===
url.pathname ===
(file.isBuildAsset ? file.browserAssetUrl : file.filePublicPath)
);
});
Expand Down
126 changes: 114 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 394c89c

Please sign in to comment.