[FileSystemRouter] Fix reload()

This commit is contained in:
Jarred Sumner
2022-11-22 21:41:34 -08:00
parent 5767ad3fc5
commit ae3fcb5bd8
2 changed files with 18 additions and 1 deletions

View File

@@ -320,7 +320,7 @@ pub const FileSystemRouter = struct {
};
var router = Router.init(vm.bundler.fs, allocator, .{
.dir = this.router.config.dir,
.dir = allocator.dupe(u8, this.router.config.dir) catch unreachable,
.extensions = allocator.dupe(string, this.router.config.extensions) catch unreachable,
.asset_prefix_path = this.router.config.asset_prefix_path,
}) catch unreachable;
@@ -338,6 +338,7 @@ pub const FileSystemRouter = struct {
this.arena = arena;
@This().routesSetCached(this_value, globalThis, JSC.JSValue.zero);
this.allocator = allocator;
this.router = router;
return this_value;
}

View File

@@ -349,6 +349,22 @@ it(".query works", () => {
}
});
it("reload() works", () => {
// set up the test
const { dir } = make(["posts.tsx"]);
const router = new Bun.FileSystemRouter({
dir,
style: "nextjs",
assetPrefix: "/_next/static/",
origin: "https://nextjs.org",
});
expect(router.match("/posts").name).toBe("/posts");
router.reload();
expect(router.match("/posts").name).toBe("/posts");
});
it(".query works with dynamic routes, including params", () => {
// set up the test
const { dir } = make(["posts/[id].tsx"]);