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

fix hmr : invalidate css files #26

Merged
merged 1 commit into from
Jan 5, 2024
Merged

Conversation

franck-co
Copy link
Contributor

fixes #11

In 5785cc8 the handleHotUpdate hook was removed.

// Re-parse .css.ts files when they change
async handleHotUpdate({file, modules}) {
	if (!cssFileFilter.test(file)) return
	try {
		const virtuals: any[] = []
		const invalidate = (type: string) => {
			const found = server.moduleGraph.getModulesByFile(`${file}${type}`)
			found?.forEach(m => {
				virtuals.push(m)
				return server.moduleGraph.invalidateModule(m)
			})
		}
		invalidate(virtualExtCss)
		invalidate(virtualExtJs)
		// load new CSS
		await server.ssrLoadModule(file)
		return [...modules, ...virtuals]
	} catch (e) {
		// eslint-disable-next-line no-console
		console.error(e)
		throw e
	}
}

It was responsible of invalidating .vanilla.css files.
Therefore it was required to do a full restart of the vite dev server to see style updates.

This PR reintroduce the invalidation of .vanilla.css files in the transform hook
to fix the HMR.

@franck-co franck-co mentioned this pull request Dec 11, 2023
Copy link
Owner

@wmertens wmertens left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@wmertens wmertens merged commit 9563939 into wmertens:main Jan 5, 2024
3 checks passed
@brandonpittman
Copy link

Has this been released?

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.

HMR not working
3 participants