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

Allow nonce to be configured for vite_react_refresh #89

Closed
mattt opened this issue Sep 11, 2023 · 1 comment · Fixed by #120
Closed

Allow nonce to be configured for vite_react_refresh #89

mattt opened this issue Sep 11, 2023 · 1 comment · Fixed by #120

Comments

@mattt
Copy link

mattt commented Sep 11, 2023

Thanks for adding the vite_react_refresh template tag in #53.

My site is configured with a Content Security Policy using django-csp. If I add {% vite_react_refresh %} in my base template and navigate to a page in my browser, the following error is printed to the console:

Refused to execute a script because its hash, its nonce, or 'unsafe-inline' does not appear in the script-src directive of the Content Security Policy.

As a workaround, I've replaced vite_react_refresh with a <script> tag that includes the generated nonce, like so:

{% if DEBUG %}
  <script type="module"
          nonce="{{ request.csp_nonce }}">
    import RefreshRuntime from 'http://localhost:5173/@react-refresh'
    RefreshRuntime.injectIntoGlobalHook(window)
    window.$RefreshReg$ = () => {}
    window.$RefreshSig$ = () => (type) => type
    window.__vite_plugin_react_preamble_installed__ = true

  </script>
{% endif %}

It'd be nice to be able to pass the nonce into vite_react_refresh as a parameter.

@Niicck
Copy link
Collaborator

Niicck commented Jan 22, 2024

This has been added to v3.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants