Skip to content

Conversation

@bluwy
Copy link
Member

@bluwy bluwy commented Nov 7, 2023

Description

In SSR, when restarting the server, the transform middleware may still be referring to the old module graph causing a ERR_CLOSED_SERVER 504 error whenever we trying to fetch /@vite/client again. Even though Vite restarts the server with new middlewares, middlewareMode will always only use the original middlewares:

).createServer({
root,
logLevel: isTest ? 'error' : 'info',
server: {
middlewareMode: true,
watch: {
// During tests we edit the files too fast and sometimes chokidar
// misses change events, so enforce polling for consistency
usePolling: true,
interval: 100,
},
hmr: {
port: hmrPort,
},
},
appType: 'custom',
customLogger,
})
// use vite's connect instance as middleware
app.use(vite.middlewares)

Additional context

I tested this in the ssr playground. You can start the server, open the page to see it work. Then update vite.config.js (a few times), then refresh the page. You'll see it failed to fetch the requests.

However, I can't seem to properly test this. The logs aren't predictable for some reason.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@bluwy bluwy added p3-minor-bug An edge case that only affects very specific usage (priority) feat: ssr labels Nov 7, 2023
@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

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

Oh, good catch! Incredible we only see this now.

I saw two more middlewares with the same problem for other config options, I'll send a separate PR.

This may be quite hard to find out for downstream projects, it is very low level but maybe we need to add this to the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: ssr p3-minor-bug An edge case that only affects very specific usage (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants