question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

hmr does not work for dependencies returned from svelte-preprocess

See original GitHub issue

Description

During svelte-preprocess, additional dependencies can be encountered and are returned as an array. Changes to these files currently do not trigger the expected hot module reload during vite dev

Reproduction

use one of the many ways to define an additional dependency by referencing a file in a svelte component that is then preprocessed. eg

<style lang="scss" src="./extra-file.scss"></style>

Additional Information

original bugreport on sveltekit: https://github.com/sveltejs/kit/issues/849

Things to do

  1. ensure the dependencies are watched correctly. For most files this should already be the case as they are inside the vite root. Call ‘addWatchFile’ anyways.
  2. ensure that edits to these files trigger hmr update
  • either by adding the files as dependencies to the respective js/css module of the .svelte file on the moduleGraph
  • or by triggering an update event on the svelte file manually

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
dominikgcommented, Apr 19, 2021

As vites importAnalysis plugin prevents us from manipulating the module graph to add the dependencies here’s an alternative approach: https://github.com/sveltejs/vite-plugin-svelte/tree/fix/watch-preprocessor-dependencies

preprocess dependencies are watched for changes and when they are changed, it triggers a change event on the parent svelte component file so standard vite handleHotUpdate mechanism runs.

https://github.com/sveltejs/vite-plugin-svelte/blob/80d448eecd13ebc69f180f0bb330a127c365e8e9/packages/vite-plugin-svelte/src/utils/preprocess.ts#L110

Tracking of dependencies/dependants is done via the compile cache

Initial tests look good: https://github.com/sveltejs/vite-plugin-svelte/blob/fix/watch-preprocessor-dependencies/packages/playground/svelte-preprocess/__tests__/svelte-preprocess.spec.ts

Thoughts?

1reaction
rixocommented, Apr 10, 2021

Tracking config files isn’t worth it. There’s so many possible cases – all of them soon expanding to .mjs, .cjs, etc – that would be a promise we cannot fully deliver, scoring at best something between deceive and disappoint, depending on user setup. Furthermore, it’s something nobody really expects, in a cold path with no high returns even if it worked… And, all in all, far more easier to handle in userland with restart plugin + I know what config files I’m actually using in my project (even that seems too much trouble to me).

The initial point of the issue, tracking code dependencies, in the hot path, is what really matters IMO.

Read more comments on GitHub >

github_iconTop Results From Across the Web

https://unpkg.com/@sveltejs/vite-plugin-svelte@1.0...
getCSS(svelteRequest); const content = await read(); const compileData = await ... log.warn("options.hot is enabled but does not work on production build, ...
Read more >
@storybook/builder-vite - npm
A plugin to run and build Storybooks with Vite. Latest version: 0.2.3, last published: 14 hours ago. Start using @storybook/builder-vite in ...
Read more >
storybook-builder-vite - NPM Package Overview - Socket - Socket.dev
An experimental plugin to run and build Storybooks with Vite. ... Package optionally loads a dependency which is not specified within any of...
Read more >
Rollup-plugin-svelte-hot - npm.io
The main reason why this plugin exists is to add support to preserve local component state over HMR updates. Svelte makes it possible...
Read more >
Why Webpack 5 is the best bundler for Svelte - codechips
Webpack might not be the sexiest bundler, but it's mature, battle-tested ... return { ... npm add -D svelte svelte-preprocess svelte-loader
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found