django-vite icon indicating copy to clipboard operation
django-vite copied to clipboard

Add tag to render the react-refresh script

Open mixxorz opened this issue 3 years ago • 4 comments

I wanted to raise another suggestion for django-vite.

When working with @vitejs/plugin-react-refresh, we need to include this script to enable HMR.

<script type="module">
  import RefreshRuntime from 'http://localhost:3000/@react-refresh'
  RefreshRuntime.injectIntoGlobalHook(window)
  window.$RefreshReg$ = () => {}
  window.$RefreshSig$ = () => (type) => type
  window.__vite_plugin_react_preamble_installed__ = true
</script>

It would be fantastic if we could have a {% vite_react_refresh_tag %} or something similar to render this script. It would only render the script if DEBUG is true.

Thanks again for your wonderful work on this library.

Ref: https://vitejs.dev/guide/backend-integration.html

mixxorz avatar Oct 19 '21 15:10 mixxorz

Duplicate of #14

MrBin99 avatar Oct 19 '21 15:10 MrBin99

Hi, As I said in the #14, I think those things are project specific stuff and need to be implemented by project.

MrBin99 avatar Oct 19 '21 15:10 MrBin99

I can see where you're coming from. Certainly, not everyone will use be using @vitejs/plugin-react-refresh.

However, in my eyes, the purpose of django-vite is to integrate Django with Vite. The @vitejs/plugin-react-refresh is part of the improved development experience that Vite provides. It's an officially supported plugin.

The approach I proposed gives users of django-vite the option to opt-in to using @vitejs/plugin-react-refresh without having to write an extra template tag.

I understand not wanting to work on this, but would you accept a PR if I opened one?

mixxorz avatar Oct 19 '21 17:10 mixxorz

Yeah of course, feel free to do it.

MrBin99 avatar Oct 19 '21 18:10 MrBin99

I think this has been done with #53 but not released yet?

burnedikt avatar May 25 '23 13:05 burnedikt

I think this has been done with #53 but not released yet?

Seems like it is released now in version 2.1.0 🎉

burnedikt avatar May 25 '23 21:05 burnedikt