From 85b57168189fa16fe966434ec50cc19425cab275 Mon Sep 17 00:00:00 2001 From: Tee Ming Date: Tue, 10 Dec 2024 22:21:12 +0800 Subject: [PATCH] fix: prevent hooks exported from `hooks.js` from overwriting hooks from `hooks.server.js` (#13104) * specifically write to each property * changeset * Update .changeset/mean-bottles-wash.md --- .changeset/mean-bottles-wash.md | 5 +++++ packages/kit/src/core/sync/write_server.js | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .changeset/mean-bottles-wash.md diff --git a/.changeset/mean-bottles-wash.md b/.changeset/mean-bottles-wash.md new file mode 100644 index 000000000000..839cfa2a8a54 --- /dev/null +++ b/.changeset/mean-bottles-wash.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: prevent hooks exported from `hooks.js` from overwriting hooks from `hooks.server.js` diff --git a/packages/kit/src/core/sync/write_server.js b/packages/kit/src/core/sync/write_server.js index eb50bfd4735b..f4568743728e 100644 --- a/packages/kit/src/core/sync/write_server.js +++ b/packages/kit/src/core/sync/write_server.js @@ -64,9 +64,19 @@ export const options = { }; export async function get_hooks() { + let handle; + let handleFetch; + let handleError; + ${server_hooks ? `({ handle, handleFetch, handleError } = await import(${s(server_hooks)}));` : ''} + + let reroute; + ${universal_hooks ? `({ reroute } = await import(${s(universal_hooks)}));` : ''} + return { - ${server_hooks ? `...(await import(${s(server_hooks)})),` : ''} - ${universal_hooks ? `...(await import(${s(universal_hooks)})),` : ''} + handle, + handleFetch, + handleError, + reroute, }; }