fix(inject-is-intersecting): Fix encapsulation, SSR safety, and shared-element subscription teardown#675
Conversation
endlacer
commented
Mar 17, 2026
- observe() now returns Observable instead of exposing the internal Subject directly, preventing consumers from calling .next(), .error(), or .complete() externally
- intersect() removed from the public interface and made private — it is an internal callback and should not be callable from outside the service
- Added isPlatformBrowser() guard in createObserver() to prevent a ReferenceError crash in SSR environments where IntersectionObserver is unavailable
- Added ref-counting via observerCounts so that when multiple components observe the same element, a single component being destroyed no longer completes the shared Subject and silently cuts off all other consumers
- Fixed incorrect first argument to assertInjector (injectDestroy → injectIsIntersecting) so injection context errors report the correct origin
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refines the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
View your CI Pipeline Execution ↗ for commit a659d6f
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Code Review
This pull request introduces several important fixes and improvements to inject-is-intersecting. The changes correctly address encapsulation by returning an Observable instead of a Subject and making internal methods private. SSR safety is improved by adding a platform check before using IntersectionObserver. The introduction of reference counting for element observers is a great fix to prevent premature teardown when an element is shared. The tests have been updated accordingly, and a new test suite for the reference counting logic has been added, which is excellent. I have one suggestion to improve the robustness of the unobserve method's logic.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces several excellent improvements to inject-is-intersecting, including fixes for encapsulation, SSR safety, and subscription teardown logic using reference counting. The changes are well-implemented and include corresponding tests for the new logic. I've suggested a minor refactoring in IsInViewportService to improve code clarity. Overall, this is a great set of improvements.