-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(remix-dev/vite): test custom server.hmr.server
vite config
#8095
test(remix-dev/vite): test custom server.hmr.server
vite config
#8095
Conversation
…custom server config
🦋 Changeset detectedLatest commit: 1ac18c4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
// TODO: should support custom server config via "unstable_createViteServer"? | ||
// https://github.com/sapphi-red/vite-setup-catalogue/blob/7ff3dd0850e5f575a01e222342f979bd70f46523/examples/middleware-mode/server.js#L12-L20 | ||
let vite = | ||
process.env.NODE_ENV === "production" | ||
? undefined | ||
: await unstable_createViteServer(); | ||
|
||
const app = express(); | ||
? undefined | ||
: await createServer({ | ||
server: { | ||
middlewareMode: true, | ||
hmr: { | ||
server, | ||
}, | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replaced unstable_createViteServer
with direct use of vite.createServer
since currently unstable_createViteServer
doesn't support passing vite config.
It might make sense to tweak the API of unstable_createViteServer
(or remove it entirely in favor of direct vite call?). Please let me know if anyone has opinion on this.
Also, FYI, using server.hmr.server
option is one of recommended setups from https://github.com/sapphi-red/vite-setup-catalogue/blob/48cde75352005aa1c1780f5eccf022db5619e285/examples/middleware-mode/server.js (explained further in sapphi-red/vite-setup-catalogue#16 and also this repo is linked from vite's documentation https://vitejs.dev/config/server-options.html#server-hmr)
I just noticed there is now basicTemplate
which includes custom server setup.
Maybe updating server.mjs
there or having a dedicated test case for this custom server scenario might make more sense.
Please let me know if there is a preferred way to test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replaced
unstable_createViteServer
with direct use ofvite.createServer
since currentlyunstable_createViteServer
doesn't support passing vite config. It might make sense to tweak the API ofunstable_createViteServer
(or remove it entirely in favor of direct vite call?). Please let me know if anyone has opinion on this.
I think that direct use of vite.createServer
is better, because if you have a need to create vite server it's because you need to customize something.
But if you want to have unstable_createViteServer
, at least allow to pass config modifications. Current implementation is not doing something special (only setting middlewareMode
) so it's not necessary.
handleUpgrade
error with custom vite server confighandleUpgrade
error with custom vite hmr server config
@hi-ogawa using |
handleUpgrade
error with custom vite hmr server configserver.hmr.server
vite config
Obsolete as we no longer ship APIs like |
EDIT: The change in this PR is obsolete after #8108 and #8120, but it might be still nice to include tests for custom
server.hmr.server
option scenario. I renamed the PR title accordingly.Closes: #7953
In #7953 (comment), @Mordred found that this is a general issue when using custom vite server config.
For the use case of child compiler, I think remix doesn't have to delegate user's vite config and also disabling
server.hmr
entirely seems appropriate.Testing Strategy
I modified
integration/vite-css-dev-express-test.ts
to use thisserver.hmr.server
config.Also, I created a reproduction with the same patch to verify the fix in https://github.com/hi-ogawa/remix-repro-7953 (or https://stackblitz.com/edit/hi-ogawa-remix-repro-7953-mum9cp?file=server.mjs)
Note that this custom server setup is useful for https server as well. You can see this use case here hi-ogawa/test-remix-vite-express-https#1.