Skip to content

fix: unregister state change listeners on disconnect - #2

Open
BatLeDev wants to merge 1 commit into
mainfrom
fix-state-change-adapter-leak
Open

fix: unregister state change listeners on disconnect#2
BatLeDev wants to merge 1 commit into
mainfrom
fix-state-change-adapter-leak

Conversation

@BatLeDev

Copy link
Copy Markdown
Member

onStateChange now returns a function to unregister the listener, which DFrameElement stores in connectedCallback() and calls in disconnectedCallback(). Applied to the three adapters: WindowStateChangeAdapter removes its popstate listener, vue-reactive returns the WatchStopHandle, vue-router returns the unregister function afterEach already provides.

Why: every mount/unmount cycle of a <d-frame> — editing a draft config, toggling dashboard columns — leaked a listener that kept firing updateSrc() on a detached element. Not a correctness bug, but a cost that grows over a long session.

Heads-up: StateChangeAdapter.onStateChange now returns () => void instead of void — a breaking type change for any external adapter written in TypeScript. No such adapter exists in our own codebases, and the runtime stays tolerant (the handle is called with ?.()).

onStateChange now returns an unregister function that DFrameElement
stores on connect and calls on disconnect. Each mount/unmount cycle
of a d-frame used to leak a vue watcher, a router afterEach hook or a
popstate listener.
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.

1 participant