refactor(observer): replace scroll-sentinel id with lvt-scroll-sentinel attribute#92
refactor(observer): replace scroll-sentinel id with lvt-scroll-sentinel attribute#92
Conversation
…inel attribute The infinite scroll sentinel was using a plain HTML id which didn't look like a framework-reserved marker and risked naming collisions. Switching to a boolean lvt-* attribute aligns with the existing convention (lvt-ignore, lvt-autofocus, lvt-focus-trap) and makes framework ownership immediately visible to developers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Review The change is clean and well-motivated — using a namespaced attribute avoids ID collisions with user code and aligns with the One deployment risk to flag: The PR description notes that E2E tests (and presumably the server-side template that renders
Otherwise, LGTM — the implementation is correct, all call sites are updated, and the test coverage is thorough. |
There was a problem hiding this comment.
Pull request overview
Refactors infinite-scroll sentinel detection to use a framework-reserved marker attribute (lvt-scroll-sentinel) instead of a plain id, reducing the risk of collisions with user-defined IDs.
Changes:
- Replaced
id="scroll-sentinel"with the boolean attributelvt-scroll-sentinelin observer logic. - Updated
ObserverManagerto locate the sentinel via an attribute selector. - Updated ObserverManager unit tests to use the new sentinel marker.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
dom/observer-manager.ts |
Switches sentinel lookup from ID to [lvt-scroll-sentinel]. |
tests/observer-manager.test.ts |
Updates tests to construct/find the sentinel using lvt-scroll-sentinel. |
Comments suppressed due to low confidence (1)
tests/observer-manager.test.ts:125
- Current tests still pass with a global
document.querySelector, so they won’t catch the multi-wrapper/multi-sentinel case introduced by switching from a uniqueidto a non-unique attribute. Add a unit test that creates two wrappers each withlvt-scroll-sentinel, setsgetWrapperElement()to one of them, and asserts the observer attaches to the sentinel within that wrapper.
it("sets up IntersectionObserver when sentinel exists", () => {
document.body.innerHTML = `
<div id="wrapper">
<div lvt-scroll-sentinel></div>
</div>
`;
mockContext = {
getWrapperElement: () => document.getElementById("wrapper"),
send: mockSend,
};
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| this.ensureUpdatedListener(wrapperElement); | ||
|
|
||
| const sentinel = document.getElementById("scroll-sentinel"); | ||
| const sentinel = document.querySelector("[lvt-scroll-sentinel]"); |
There was a problem hiding this comment.
document.querySelector("[lvt-scroll-sentinel]") searches the whole document and will pick the first matching sentinel if multiple LiveTemplate wrappers (or multiple sentinels) exist on the page. With the old id, uniqueness was enforced; with a boolean attribute it’s not. Consider scoping the lookup to the current wrapper (e.g., wrapperElement.querySelector(...)) so each ObserverManager instance observes its own sentinel.
| const sentinel = document.querySelector("[lvt-scroll-sentinel]"); | |
| const sentinel = wrapperElement.querySelector("[lvt-scroll-sentinel]"); |
Scopes querySelector to the wrapper instead of document, so each ObserverManager instance only observes the sentinel within its own wrapper. Prevents cross-wrapper detection when multiple LiveTemplate instances exist on the same page. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Review of #92 — scroll-sentinel attribute refactor The core change is correct and an improvement: scoping the lookup to One concern: coordinated deployment This is a breaking change that requires the server-side template to be updated in lockstep. If the server still emits Minor: non-standard attribute
Otherwise the implementation is clean and the tests are thorough. LGTM pending the deployment coordination note above. |
Summary
id="scroll-sentinel"with the boolean attributelvt-scroll-sentinelfor infinite scroll detectiongetElementByIdtoquerySelector("[lvt-scroll-sentinel]")in observer-managerTest plan
examples/andlvt/repos (separate PRs)🤖 Generated with Claude Code