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

HMR is raising a preload warning in console #247

Closed
2 tasks done
npearson72 opened this issue Sep 4, 2022 · 2 comments
Closed
2 tasks done

HMR is raising a preload warning in console #247

npearson72 opened this issue Sep 4, 2022 · 2 comments
Labels
bug: pending triage Something doesn't seem to be working, but hasn't been verified

Comments

@npearson72
Copy link

  • I have tried upgrading by running bundle update vite_ruby.
  • I have read the troubleshooting section before opening an issue.

Description 📖

Using vite_client_tag, I'm seeing the following in my browser's console:

The resource http://localhost:3001/vite-dev/@vite/client was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.

I can't share too much in the way of logs or any other details because of the nature of project, but I can share that adding defer: true to the helper fixes the issue:

Example:

  def vite_client_tag
    return unless src = vite_manifest.vite_client_src

    javascript_include_tag(src, type: 'module', extname: false, defer: true)
  end

I believe defer: true is the correct option here, though not 100% familiar with how HMR is processed in Vite.

If this is an issue anyone else is having, I'd be happy to add a PR for it. Otherwise, just use this report as point of reference.

@npearson72 npearson72 added the bug: pending triage Something doesn't seem to be working, but hasn't been verified label Sep 4, 2022
@ElMassimo
Copy link
Owner

ElMassimo commented Sep 4, 2022

Hi Nathan, thanks for reporting.

Probably related to the combination of an old Rails version and:

It's likely that you are running in an environment where early response hints are enabled, and Rails is sending a header to let the browser preload the script.

The mismatch is probably related to the fact that the client script is a module, and you are running in an old Rails version that sends hints incorrectly for module scripts.

I've fixed Rails behavior in:

See this discussion for ways to address this problem in your app.

@npearson72
Copy link
Author

I deleted my previous comments. You're right. After taking a closer look it seems my version of Rails does not include your patch to the javascript_include_tag helper.

Sorry to bother you.

Thanks for the awesome library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: pending triage Something doesn't seem to be working, but hasn't been verified
Projects
None yet
Development

No branches or pull requests

2 participants