Noan
Noan
NNuxt
Created by Noan on 1/1/2025 in #❓・help
Custom Module composable state not reset after hot reload
I wanted to learn how to do nuxt modules so I made this: https://github.com/Waradu/keyboard the problem is in src/runtime/keyboard.ts > handlers. If the application hot reloades the "new" event get added but the old one are still in the list. Example testapp:
<template>TEST</template>

<script lang="ts" setup>
import { Key } from "wrdu-keyboard/key";

const keyboard = useKeyboard();

keyboard.down([Key.A], () => {
console.log("pressed");
});
</script>
<template>TEST</template>

<script lang="ts" setup>
import { Key } from "wrdu-keyboard/key";

const keyboard = useKeyboard();

keyboard.down([Key.A], () => {
console.log("pressed");
});
</script>
if I now change "pressed" to "pressed2" while running dev mode and the application hot reloads, it prints "pressed" and "pressed2". Printing "handlers" from keyboard.ts shows that there are 2 KeyHandlers instead of 1. Why is that and how to fix?
5 replies