Skip to content

Conversation

eduardoboucas
Copy link
Member

I noticed that I would get errors in functions when using the Vite plugin and making multiple requests to the same function. I realised that this is because, unlike the CLI, in the Vite plugin we're not watching files for changes. We're just calling the handle() function on requests and that will cause functions to be built with the latest state of their source files.

In practice, this meant that we could have multiple function builders writing to the .netlify/functions-serve directory, which was breaking things.

This PR introduces two changes:

  1. We stop building all functions automatically, and instead we lazily build only the function that matches the incoming request
  2. We make each function builder write to an ephemeral directory inside .netlify/functions-serve, so that multiple builders are not destroying each other's working directories; these directories are cleaned up after each invocation

It depends on netlify/build#6353, so it's expected that tests will fail until it has been merged and released, but I wanted to have the PR up for review sooner rather than later.

serhalp
serhalp previously approved these changes May 22, 2025
Copy link
Member

@serhalp serhalp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eduardoboucas eduardoboucas merged commit a749e26 into main May 22, 2025
23 checks passed
@eduardoboucas eduardoboucas deleted the fix/functions-ephemeral-directories branch May 22, 2025 22:33
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

Successfully merging this pull request may close these issues.

2 participants