[PR #20913] [MERGED] fix: clean up all event listeners in +layout.svelte onMount #41458

Closed
opened 2026-04-25 13:42:17 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/20913
Author: @sjhddh
Created: 1/23/2026
Status: Merged
Merged: 1/29/2026
Merged by: @tjbck

Base: devHead: fix/layout-memory-leak


📝 Commits (1)

  • c4a5c45 fix: clean up all event listeners in +layout.svelte onMount

📊 Changes

1 file changed (+15 additions, -7 deletions)

View changed files

📝 src/routes/+layout.svelte (+15 -7)

📄 Description

Summary

Fix memory leaks in +layout.svelte by properly cleaning up all event listeners added in onMount.

Problem

The onMount hook adds event listeners for message, touchstart, touchmove, touchend, visibilitychange, and resize, but the cleanup function only removes the resize listener. The anonymous touch handlers cannot be removed because they have no reference. This causes memory leaks during navigation and hot-reloads.

Solution

  1. Extract anonymous touch event handlers into named functions (touchstartHandler, touchmoveHandler, touchendHandler)
  2. Add { passive: false } to touchmove listener to allow preventDefault()
  3. Update the onMount cleanup function to remove all event listeners

Fixed

  • Memory leaks caused by unremoved event listeners during component unmount
  • Touch event handlers now properly cleaned up on navigation

Changed

  • Refactored anonymous touch handlers into named functions for proper cleanup

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/20913 **Author:** [@sjhddh](https://github.com/sjhddh) **Created:** 1/23/2026 **Status:** ✅ Merged **Merged:** 1/29/2026 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `fix/layout-memory-leak` --- ### 📝 Commits (1) - [`c4a5c45`](https://github.com/open-webui/open-webui/commit/c4a5c4577defcb107514c59d3297dc8647786ae8) fix: clean up all event listeners in +layout.svelte onMount ### 📊 Changes **1 file changed** (+15 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `src/routes/+layout.svelte` (+15 -7) </details> ### 📄 Description ## Summary Fix memory leaks in `+layout.svelte` by properly cleaning up all event listeners added in `onMount`. ## Problem The `onMount` hook adds event listeners for `message`, `touchstart`, `touchmove`, `touchend`, `visibilitychange`, and `resize`, but the cleanup function only removes the `resize` listener. The anonymous touch handlers cannot be removed because they have no reference. This causes memory leaks during navigation and hot-reloads. ## Solution 1. Extract anonymous touch event handlers into named functions (`touchstartHandler`, `touchmoveHandler`, `touchendHandler`) 2. Add `{ passive: false }` to `touchmove` listener to allow `preventDefault()` 3. Update the `onMount` cleanup function to remove **all** event listeners ### Fixed - Memory leaks caused by unremoved event listeners during component unmount - Touch event handlers now properly cleaned up on navigation ### Changed - Refactored anonymous touch handlers into named functions for proper cleanup --- ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-25 13:42:17 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#41458