Skip to content

Commit

Permalink
fix: prevent hooks exported from hooks.js from overwriting hooks fr…
Browse files Browse the repository at this point in the history
…om `hooks.server.js` (#13104)

* specifically write to each property

* changeset

* Update .changeset/mean-bottles-wash.md
  • Loading branch information
eltigerchino authored Dec 10, 2024
1 parent 7168778 commit 85b5716
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-bottles-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: prevent hooks exported from `hooks.js` from overwriting hooks from `hooks.server.js`
14 changes: 12 additions & 2 deletions packages/kit/src/core/sync/write_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
Expand Down

0 comments on commit 85b5716

Please sign in to comment.