As the author of TresJS I wish I could differentiate when an HMR update hook (import.meta.hot.on('vite:beforeUpdate')) is triggered by a change on an <template> on a Vue SFC component and when is triggered from a <script setup /> block.
The reason is we need to dispose of 3D scene objects on HMR
The problem is that this code works well when the change comes from the template, but if the change comes from the script tag the creation of 3D instances is loaded again, causing duplicate objects on the scene
I checked the value coming from both vite:beforeUpdate and vite:afterUpdate but I don't see any info that could help me differentiate between both
Description
As the author of TresJS I wish I could differentiate when an HMR update hook (
import.meta.hot.on('vite:beforeUpdate')
) is triggered by a change on an<template>
on a Vue SFC component and when is triggered from a<script setup />
block.The reason is we need to dispose of 3D scene objects on HMR
The problem is that this code works well when the change comes from the template, but if the change comes from the script tag the creation of 3D instances is loaded again, causing duplicate objects on the scene
I checked the value coming from both
vite:beforeUpdate
andvite:afterUpdate
but I don't see any info that could help me differentiate between bothSuggested solution
Would be possible if we modify the
updateModules
method on /packages/vite/src/node/server/hmr.ts#L156 to return the complete boundary object.With that we could send the
updateType
from vite-plugin-vue/packages/plugin-vue/src/handleHotUpdate.ts#L170 by modifying the return statement to thisI tested it locally and works, but I want to confirm if it's something you would consider before creating the PR in both places
Alternative
I can't think right now of an alternative that could solve the HMR issue.
Additional context
No response
Validations