fix(components): prevent memory leaks by using takeUntil and managing subscriptions#99
Conversation
📝 WalkthroughWalkthroughThis pull request implements systematic subscription lifecycle management across multiple components and services to prevent memory leaks. Changes introduce automatic unsubscription patterns using both Angular's Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.41.1)booklore-ui/src/app/features/readers/ebook-reader/core/event.service.ts[ ... [truncated 16836 characters] ... 14 Comment Tip CodeRabbit can use OpenGrep to find security vulnerabilities and bugs across 17+ programming languages.OpenGrep is compatible with Semgrep configurations. Add an |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
booklore-ui/src/app/features/readers/pdf-reader/pdf-reader.component.ts (1)
68-70: Consider usingtakeUntilfor consistency.The
annotationSaveSubscriptionis manually unsubscribed while other subscriptions usetakeUntil(this.destroy$). For consistency, you could apply the same pattern here.♻️ Optional: Use takeUntil for consistency
- this.annotationSaveSubscription = this.annotationSaveSubject + this.annotationSaveSubject .pipe(debounceTime(1500)) + .pipe(takeUntil(this.destroy$)) .subscribe(() => this.persistAnnotations());Then remove the manual unsubscribe at line 184:
- this.annotationSaveSubscription?.unsubscribe();🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@booklore-ui/src/app/features/readers/pdf-reader/pdf-reader.component.ts` around lines 68 - 70, The subscription created from annotationSaveSubject should use takeUntil(this.destroy$) for consistency: change the chain to this.annotationSaveSubject.pipe(debounceTime(1500), takeUntil(this.destroy$)).subscribe(() => this.persistAnnotations()); then remove the manual unsubscribe of annotationSaveSubscription in the component teardown (and you can remove the annotationSaveSubscription field if it’s no longer used). This keeps behavior identical while matching other subscriptions that use destroy$.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@booklore-ui/src/app/features/readers/pdf-reader/pdf-reader.component.ts`:
- Around line 68-70: The subscription created from annotationSaveSubject should
use takeUntil(this.destroy$) for consistency: change the chain to
this.annotationSaveSubject.pipe(debounceTime(1500),
takeUntil(this.destroy$)).subscribe(() => this.persistAnnotations()); then
remove the manual unsubscribe of annotationSaveSubscription in the component
teardown (and you can remove the annotationSaveSubscription field if it’s no
longer used). This keeps behavior identical while matching other subscriptions
that use destroy$.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0db722f1-c47c-4aa4-9c9e-4f3195ed2186
📒 Files selected for processing (11)
booklore-ui/src/app/app.component.tsbooklore-ui/src/app/features/book/components/book-browser/book-table/book-table.component.tsbooklore-ui/src/app/features/dashboard/components/dashboard-settings/dashboard-settings.component.tsbooklore-ui/src/app/features/dashboard/components/main-dashboard/main-dashboard.component.tsbooklore-ui/src/app/features/readers/cbx-reader/cbx-reader.component.tsbooklore-ui/src/app/features/readers/ebook-reader/core/event.service.tsbooklore-ui/src/app/features/readers/ebook-reader/ebook-reader.component.tsbooklore-ui/src/app/features/readers/ebook-reader/layout/sidebar/sidebar.service.tsbooklore-ui/src/app/features/readers/pdf-reader/pdf-reader.component.tsbooklore-ui/src/app/features/settings/file-naming-pattern/file-naming-pattern.component.tsbooklore-ui/src/app/shared/layout/component/layout-menu/app.menu.component.ts
Description
Linked Issue: Fixes #
Changes
This PR refactor few component that had potential for memory leaks.
Main changes are the following:
Summary by CodeRabbit