Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooks stopped working after upgrading #14747

Closed
MattPhantastic opened this issue Dec 18, 2024 · 2 comments
Closed

Hooks stopped working after upgrading #14747

MattPhantastic opened this issue Dec 18, 2024 · 2 comments

Comments

@MattPhantastic
Copy link

MattPhantastic commented Dec 18, 2024

Describe the bug

After following these two issues:

  1. Cannot read properties of undefined (reading 'startsWith') vite-plugin-svelte#1053
  2. TypeScript nodes still causing code generation failures #14743

I've upgraded my Svelte version to the, as of current, latest 5.14.3. Hooks have completely stopped working for me. I can't even write a string to the console. My src/hooks.ts is essentially being ignored.

Reproduction

  1. Install new a new project with the latest version of SvelteKit
  2. Create a src/hooks.ts file:
import type { Handle } from "@sveltejs/kit";
export const handle: Handle = async ({ event, resolve }) => {
  console.log("Hooks?");
  const response = await resolve(event);
  return response;
};

Logs

No response

System Info

System:
  OS: macOS 14.6.1
  CPU: (8) arm64 Apple M2
  Memory: 120.38 MB / 8.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 20.18.0 - ~/Library/pnpm/node
  npm: 10.8.2 - ~/Library/pnpm/npm
  pnpm: 9.12.3 - ~/Library/pnpm/pnpm
Browsers:
  Brave Browser: 131.1.73.101
  Safari: 17.6
npmPackages:
  svelte: ^5.14.3 => 5.14.3 

Severity

blocking an upgrade

@cloudymeatball
Copy link

cloudymeatball commented Dec 18, 2024

handle is only available in hooks.server.js/ts.

Right now if using handle in universal hook, it is typed as

({ event, resolve }: {
    event: any;
    resolve: any;
}) => Promise<any>

It may be less confusing to type it as never, along with a note that it is only available in server-side hooks.

EDIT: Also ideally a warning is given when trying to import server hook types such as Handle into non-server hooks. Personally I'm not sure how easy it is to implement such a warning or error.

@paoloricciuti
Copy link
Member

As pointed out handle is only available in hooks.server.ts...this was a bug in kit that was fixed in sveltejs/kit#13104

You can just move your hook to hooks.server.ts, therefore closing this but thanks for reporting

@paoloricciuti paoloricciuti closed this as not planned Won't fix, can't repro, duplicate, stale Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants