`handle` can run when endpoint functions are not exported
See original GitHub issueDescribe 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:
- Created a year ago
- Comments:8 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.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. Thatfetch
request is what’s triggeringhandle
.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.Creating a
.ts
file that starts with an underscore does not generate aRequestHandler
type.Since this file is for utility purpose only, I guess I should convert it into a standalone endpoint.
Thank you once again.