Skip to content
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

feat: use a single transport for fetchModule and HMR support #18362

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Oct 16, 2024

Description

so that env providers not need to implement both fetchModule transport and HMR transport.

I think this PR still needs to polish the naming and probably better to introduce a interface that wraps HotChannel so that env providers does not need to care about internal conversion that is done for send and invoke (done).

image
The upper part is how it was before and the lower part is how it is after.

@sapphi-red sapphi-red added the feat: environment API Vite Environment API label Oct 16, 2024
Copy link

stackblitz bot commented Oct 16, 2024

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

@sapphi-red
Copy link
Member Author

sapphi-red commented Oct 17, 2024

I polished the interface so that it's more easier to implement for the env providers. I think we need a better name and check if this is not breaking a code that was working in 5.x.

@sheremet-va
Copy link
Member

@bluwy pointed out the inconsistency in the naming of RunnerTransport in #16358 (comment)

Should we also standardise it here?

@sapphi-red

This comment was marked as outdated.

@vite-ecosystem-ci

This comment was marked as outdated.

@sapphi-red
Copy link
Member Author

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on 38b50bf: Open

suite result latest scheduled
astro failure failure
remix failure failure
sveltekit failure failure
vike failure failure
vite-environment-examples failure success
vitest failure failure

analogjs, histoire, ladle, laravel, marko, nuxt, previewjs, quasar, qwik, rakkas, redwoodjs, storybook, unocss, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-svelte, vite-plugin-vue, vite-setup-catalogue, vitepress, vuepress

@sapphi-red sapphi-red marked this pull request as ready for review October 18, 2024 14:16
@sapphi-red
Copy link
Member Author

sapphi-red commented Oct 18, 2024

I've updated the docs (maybe it should contain a bit more explaination about the HotChannel). It's now ready.

This is how the diff looks like after this PR: sapphi-red/daienjo-architecture@804cb53


I'm not going to implement it in this PR, but it would be nice if we can use the default WebSocketServer for multiple envs. For example, using it from the service worker env as well.

options.hmr.connection.onUpdate(createHMRHandler(this))
hmrHandlerForTransport = createHMRHandler(this)
if (!this.transport.connect) {
resolvedHmrLogger.error('HMR is not supported by this runner transport')
Copy link
Member

Choose a reason for hiding this comment

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

Should we throw an error instead? 🤔 If hmr is provided, then I would assume the transport supports it

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed the way in f08a2df and fddfd64, along with the following comments.

packages/vite/src/module-runner/runner.ts Outdated Show resolved Hide resolved
packages/vite/src/module-runner/runner.ts Outdated Show resolved Hide resolved
packages/vite/src/node/server/environment.ts Outdated Show resolved Hide resolved
@sapphi-red
Copy link
Member Author

Exported env.getInvokeHandler (7536dfb) and tweaked some types (05413c6) to reduce required knowledge on the runtime provider side (sapphi-red/daienjo-architecture@6b91f25).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: environment API Vite Environment API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants