8000 Memory leak: Vue effect needs cleanup in toUnSignal function · Issue #11 · un-ts/unuse · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Memory leak: Vue effect needs cleanup in toUnSignal function #11
Open
@coderabbitai

Description

@coderabbitai

Problem

The toUnSignal function in packages/unuse/src/toUnSignal/index.ts creates a Vue effect for bidirectional sync without proper cleanup, causing a memory leak when Vue components are unmounted.

Location

Around lines 159-163 in packages/unuse/src/toUnSignal/index.ts, the effect() from alien-signals lacks cleanup:

if (!Vue.isReadonly(value)) {
  effect(() => {
    (value as VueRef<T>).value = result.get();
  });
}

Proposed Solution

Capture the dispose function returned by effect() and call it in an onUnmounted hook:

if (!Vue.isReadonly(value)) {
  const dispose = effect(() => {
    (value as VueRef<T>).value = result.get();
  });
  Vue.onUnmounted(() => dispose());
}

References

Notes

Need to ensure onUnmounted is available in the current context or use an alternative cleanup mechanism.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0