Skip to content

Commit

Permalink
feat(server): prevent vite hmr from being hijacked by default
Browse files Browse the repository at this point in the history
Specifying a default websocket handler will most definitely cause issues with Vite, so we now ignore it by default!
  • Loading branch information
Pkmmte committed May 2, 2024
1 parent 0748de7 commit 0113987
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fifty-cooks-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@robojs/server': minor
---

feat: prevent vite hmr from being hijacked by default
7 changes: 6 additions & 1 deletion packages/plugin-api/src/events/_start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ export default async (_client: Client, options: PluginOptions) => {
}
}

// Setup Vite if available
// Setup Vite if available and register socket bypass
if (vite) {
await engine.setupVite(vite)

// Prevent other plugins from registering the HMR route
engine.registerWebsocket('/hmr', () => {
logger.debug('Vite HMR connection detected. Skipping registration...')
})
}

// Add loaded API modules onto new router instance
Expand Down

0 comments on commit 0113987

Please sign in to comment.