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 in linked dependencies don't cause hmr #38

Closed
Bohreromir opened this issue Mar 22, 2021 · 14 comments
Closed

Changes in linked dependencies don't cause hmr #38

Bohreromir opened this issue Mar 22, 2021 · 14 comments
Labels
bug Something isn't working

Comments

@Bohreromir
Copy link
Contributor

If there is a <script> or css load inside of a partial, it seems like changes in that file won't trigger a reload.

@alexlafroscia
Copy link
Owner

Hmm... That’s odd. From Vite’s perspective, the partial is part of the HTML file it’s injected into, so I would expect this to work correctly.

I’ll do some investigation locally and see if I can reproduce that error; I haven’t noticed the problem myself, but I’m using Tailwind in the project I made this plugin for, so I don’t really ever edit my CSS file!

@alexlafroscia alexlafroscia added the bug Something isn't working label Mar 22, 2021
@Bohreromir
Copy link
Contributor Author

This is what im dealing with. Changes to the scss don't trigger a reload, neither do linked scripts in the base.html when browsing to page.html.

page.html

{{#> base }}
    <h1> Some page content </h1>
{{/ base }}

base.hbs

[...]
<head>
     <link rel="stylesheet" href="../assets/styles/main.scss">
</head>
<body>
    {{> @partial-block }}
</body>
[...]

@alexlafroscia
Copy link
Owner

Can you try changing your <link> tag to an absolute URL rather than a relative one? Just see if that fixes things at all.

@Bohreromir
Copy link
Contributor Author

Bohreromir commented Mar 22, 2021

Same behavior as before.

Could be a vite bug, this issue sounds familiar:
vitejs/vite#2633

@alexlafroscia
Copy link
Owner

Interesting! Let's keep an eye on the Vite bug and see if that's the culprit; I don't want to shirk responsibility but it's unlikely that the issue here has something to do with this plugin since, from Vite's perspective, the resolved file with all of it's partials are just a single HTML file that it would process as usual.

@Bohreromir
Copy link
Contributor Author

I did some test, and for me it looks like, as soon as the plugin loads hmr breaks.
This is just:

  plugins: [
    handlebars()
  ],

and the default vite startertemplate:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="favicon.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite App</title>
  </head>
  <body>
    <div id="app"></div>
    
    <script type="module" src="/main.js"></script>
  </body>
</html>

vite --debug shows it recognises the changes, but doesnt know how to handle it.
image

@alexlafroscia
Copy link
Owner

Very interesting! Thanks for investigating a bit more. My job has me pretty busy so I won't be able to look into this the next few days, during the day, at least, but I'll try to look into this more this weekend!

If you're able to post a repo somewhere with a set-up that makes it easy for me to reproduce the issue, that would go a long way toward helping me get this addressed quickly!

@Bohreromir
Copy link
Contributor Author

Bohreromir commented Mar 25, 2021

Sure! https://github.com/Bohreromir/vite-hmr-bug-test
Thanks for having a look

@alexlafroscia
Copy link
Owner

Got it! Thanks!

@alexlafroscia
Copy link
Owner

Your reproduction repo was super helpful! It turns out that returning an empty array basically blocked all modules from being hot-reloaded.

I tried to write a test against this in the codebase here but there's really no way to hook in and check whether the event was emitted or not. I did try this out locally, though, and it's working now!

@alexlafroscia
Copy link
Owner

Released in 1.4.2 -- let me know if that doesn't seem to fix your issue!

@Bohreromir
Copy link
Contributor Author

Looks good to me, thanks!

@pierremouchan
Copy link

Hello! Seem to have the same exact bug there ;)
Here is my packages version:

    "vite-plugin-handlebars": "^1.6.0"    
    "vite": "^2.7.13"

@pierremouchan
Copy link

Hello! Seem to have the same exact bug there ;) Here is my packages version:

    "vite-plugin-handlebars": "^1.6.0"    
    "vite": "^2.7.13"

Problem found!
I was using type: "modules" inside my package json file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants