Skip to content

feat(vite): inject react refresh when needed #1406

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

Merged

Conversation

NeoIsRecursive
Copy link
Contributor

Using the vite react plugins requires this snippet to be present:

Note if you are using React with @vitejs/plugin-react, you'll also need to add this before the above scripts, since the plugin is not able to modify the HTML you are serving (substitute http://localhost:5173 with the local URL Vite is running at):

<script type="module">
 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>

This PR adds so the vite plugin detects if this needs to be injected, adds a bool to the bridgefile that the DevelopmentTagsResolver reads and injects the "snippet".

One improvement to this would be to use the TagCompiler so the nonce and other things would be set, but that would require some changes there (public body setting support), I think atleast.

@NeoIsRecursive NeoIsRecursive changed the title feat(vite): injectreact refresh injection feat(vite): inject react refresh if needed Jul 12, 2025
@brendt brendt requested a review from innocenzi July 12, 2025 17:12
@innocenzi innocenzi changed the title feat(vite): inject react refresh if needed feat(vite): inject react refresh when needed Jul 16, 2025
@innocenzi innocenzi merged commit b57bf7f into tempestphp:main Jul 16, 2025
71 checks passed
@innocenzi
Copy link
Member

Works perfectly, thank you!

@NeoIsRecursive NeoIsRecursive deleted the feature/react-refresh-injection branch July 16, 2025 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants