question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`handle` can run when endpoint functions are not exported

See original GitHub issue

Describe the bug

Empty .js or .ts file that does not export any endpoint functions (eg. GET) can still trigger handle.

Reproduction

Used create-svelte@2.0.0-next.149 and SvelteKit demo app template.

Prerequisite

Log request method and pathname in the beginning of the handle function.

export const handle: Handle = async ({ event, resolve }) => {
	const { request: { method }, url: { pathname } } = event;
	console.log(method, pathname);
...

Control Group

Run vite dev, open /, then navigate to /about.

  VITE v3.0.2  ready in 205 ms

  ➜  Local:   http://localhost:5174/
  ➜  Network: use --host to expose

GET /

Experimental Group

Create a blank about.ts file alongside about.svelte

├── __layout.svelte
├── about.svelte
├── about.ts // Created
├── index.svelte
└── todos
    ├── _api.ts
    ├── index.svelte
    └── index.ts

Run vite dev, open /, then navigate to /about.

  VITE v3.0.2  ready in 199 ms

  ➜  Local:   http://localhost:5174/
  ➜  Network: use --host to expose

GET /
GET /about

GET /about is logged in the experimental group only.

System Info

System:
  OS: macOS 12.4
  CPU: (8) arm64 Apple M1
  Memory: 92.70 MB / 8.00 GB
  Shell: 5.8.1 - /bin/zsh
Binaries:
  Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
  npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
Browsers:
  Chrome: 103.0.5060.134
  Firefox: 102.0
  Safari: 15.5

Severity

annoyance

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
tcc-sejohnsoncommented, Jul 24, 2022

I was expecting Page Endpoint requests only when there is a matching request handler function.

The client has no idea what functions are exported from the server AFAIK. The existence of a matching .ts file determines whether the page gets built with a page endpoint.

Since there is no GET request handler exported from the about.ts (experimental group), I was expecting a client-side navigation, just like in the control group. (when opening / and then navigating to /about)

You are getting client-side navigation. It’s just that your page is making a fetch request to its page endpoint for data because you put a matching .ts file in there. That fetch request is what’s triggering handle.

Opening /about directly or hard reloading the page does log GET /about in both cases.

Yep, expected.

TL;DR: Don’t create a matching .ts file if you don’t want your page to try to fetch from its page endpoint.

0reactions
hyunbinseocommented, Jul 24, 2022

Creating a .ts file that starts with an underscore does not generate a RequestHandler type.

Since this file is for utility purpose only, I guess I should convert it into a standalone endpoint.

Thank you once again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deploy Only Single Non-exported Function in Firebase Cloud ...
The CLI can only individually deploy exported function triggers. It can not specifically deploy any arbitrary JavaScript named function.
Read more >
Internal functions in R packages - R-hub blog
For instance, in the usethis package there's a base_and_recommended() function that is not exported. # doesn't work library("usethis") ...
Read more >
AWS Lambda function handler in Node.js
When your function is invoked, Lambda runs the handler method. When the handler exits or returns a response, it becomes available to handle...
Read more >
Manage functions | Cloud Functions for Firebase - Google
You can deploy, delete, and modify functions using Firebase CLI commands or by setting runtime ... To deploy functions, run this Firebase CLI...
Read more >
Data Fetching: getStaticProps - Next.js
If you export a function called getStaticProps (Static Site Generation) from a page, Next.js will ... The data can be publicly cached (not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found