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

Changes to external css file or external ts file used in svelte file does not trigger reload with HMR #2633

Closed
3 tasks done
NiQ-B opened this issue Mar 22, 2021 · 7 comments
Closed
3 tasks done

Comments

@NiQ-B
Copy link

NiQ-B commented Mar 22, 2021

⚠️ IMPORTANT ⚠️ Please do not ignore this template. If you do, your issue will be closed immediately.

Describe the bug

A clear and concise description of what the bug is.
Changes to external .css files or external .ts files configured as src documents in the svelte file does not trigger hot module reload. A save on the parent svelte file is required to trigger the update.

Inline style and script ts tags and code works as expected with hmr.

After testing on both a sveltekit@next and vite svelte ts template, I have narrowed down the issue to vite or vite - svelte-preprocessor integration.

Have tried to add css files to the vite.config.js server.watch options with a src/**/*.css glob.

// https://vitejs.dev/config/
export default defineConfig({
server: {
watch: [
'src/**/*.css'
]
},
clear: false,
plugins: [svelte()]
})

See relevant log items below, vite shows that the change is recognized by watch but does not have a module to update even though the src attribute has the name.

Logs (Optional if provided reproduction)

vite:hmr [file change] src/_index.css +4m
vite:hmr [no modules matched] src/_index.css +0m

<script lang="ts" src='_index.ts'/>
<style lang='sugarss' src='_index.css'/>

<!-- prettier-ignore -->
<template lang='pug'>
  div(class="m-title")
    .flex.item-center.justify-center
      | This is a test
</template>

Reproduction

_index.css - contents

 .m-title
   @apply text-7xl mt-[400px] text-indigo-800

Please provide a link to a repo that can reproduce the problem you ran into.

A reproduction is required unless you are absolutely sure that the the problem is obvious and the information you provided is enough for us to understand what the problem is. If a report has only vague description (e.g. just a generic error message) and has no reproduction, it will receive "need reproduction" label. If no reproduction is provided after 3 days, it will be auto-closed.

System Info

  • vite version: 2.1.0
  • Operating System: ubuntu 18.04
  • Node version: 14.13.0
  • Package manager (npm/yarn/pnpm) and version: yarn 1.22.5

Logs (Optional if provided reproduction)

vite:hmr [file change] src/_index.css +4m
vite:hmr [no modules matched] src/_index.css +0m

  1. Run vite or vite build with the --debug flag.
  2. Provide the error log here.
@wheatjs
Copy link

wheatjs commented Mar 22, 2021

Can you provide a link to a repo with a reproduction

@NiQ-B
Copy link
Author

NiQ-B commented Mar 22, 2021

@jacobclevenger thank you for the quick response. Here is a link to the public repo.
I added a plugin to do hmr login as well.
https:/NiQ-B/test-vite

@ambrt
Copy link

ambrt commented Oct 4, 2021

I have similar issue with with imported css.
Actually HMR is called on css modification (according to log in terminal)
but old value of css file is still active.

I do workaround directly with import.meta.hot.on and manual cache buster


import green from "../css/test2.css?inline"

if (import.meta.hot) {
        import.meta.hot.on("vite:beforeUpdate", () => {
            console.log("vite before update");

            // TODO: Fix Memory leak
            // https://stackoverflow.com/questions/56492656/how-to-reimport-module-with-es6-import#comment111734170_58153757
       
            import("../css/test2.css?inline&cachebuster" + Date.now()).then(
                (module) => {
                    green2 = module;
                }
            );
        });
    }


PS. There is "new" css imported every time due to cache buster and it's been said that its
an memory leak. Terminal show that vite tracks each of past imported files as separate instances.
Link in code comment points to a way to remove memory leak but i haven't tested
how vite will log or work with it, yet.

@ambrt
Copy link

ambrt commented Oct 4, 2021

Link in code comment points to a way to remove memory leak but i haven't tested
how vite will log or work with it, yet.

TL;DR: Until something changes in ESM, leak is unsolved and eventually will fill up all ram.
source:
https://ar.al/2021/02/22/cache-busting-in-node.js-dynamic-esm-imports/

Also vite log will point to every past link in one big wall of "hmr update /css...."

@bluwy
Copy link
Member

bluwy commented Oct 11, 2021

Can't reproduce this with https:/NiQ-B/test-vite, the changes in the external files trigger HMR immediately after updating to the latest version of https:/sveltejs/vite-plugin-svelte. @ambrt Do you have a repro too? IIUC vite-plugin-svelte should be handling this scenario's well. We should report the issue there too.

@ambrt
Copy link

ambrt commented Dec 13, 2021

@bluwy My code is for SvelteKit and somewhere between now and time at which i created my app changes must have been made, because newest init skeleton app for SvelteKit now refresh external css in proper way.

So for me issue can be closed, not sure about @NiQ-B

@bluwy
Copy link
Member

bluwy commented Dec 14, 2021

Thanks for the update @ambrt. @NiQ-B haven't responded in a while, and I can't reproduce this, so I'll go ahead and close this issue.

@bluwy bluwy closed this as completed Dec 14, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants