Fix lens drift when multiple in-flow lenses collapse the snapshot#7
Open
codedgar wants to merge 1 commit into
Open
Fix lens drift when multiple in-flow lenses collapse the snapshot#7codedgar wants to merge 1 commit into
codedgar wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a snapshot/coord mismatch in
captureSnapshotthat caused every.liquidGLlens to refract the wrong region when multiple lenses sat in normal document flow on a long page. The misalignment compounded with depth, each additional lens above contributed to the offset.Root cause
captureSnapshotpassed lens elements into html2canvas'signoreElementscallback. html2canvas honorsignoreElementsby settingdisplay: noneon those elements in its cloned DOM, which collapses them out of layout. Any element below a collapsed lens shifts up in the snapshot by that lens's height.Lens sampling math in
_renderLens(scripts/liquidGL.js:686–688) reads the lens position from the live DOM:Live coords no longer match snapshot coords, so the UV sample lands in the wrong place. With N lenses above a given lens, the cumulative collapse is N × lens-height, so the offset grows the deeper into the page you go. Lenses with
position: absolutemostly hid the bug because they don't contribute to flow; lenses in normal flow (block-level) make it obvious.Fix
Stop using
ignoreElementsto remove lens elements. Instead:data-liquidgl-hideattribute before calling html2canvas (attribute mutation only — no visual repaint).onclone(clonedDoc)handler that finds those tagged elements in the clone and setsvisibility: hidden.visibility: hiddenpreserves the element's box in layout but doesn't paint its content — so the snapshot doesn't double-render the lens, and live-DOM coords match snapshot coords exactly. The data-attribute approach matches the existingdata-liquid-ignorepattern already inignoreElementsFunc.Reproducing
A long page with 4+ block-level
.liquidGLelements interspersed with content (e.g. between sections) reproduces the bug onmain. Each lens refracts content from a position that drifts further from its true backdrop the lower it sits. The first lens is also affected because its own collapse shifts content positioned within its parent gap.Try the demo
Open
/demos/comparison.html— side-by-side panes showing the upstream build (left) vs the patched fork (right) on the same scene. Scroll either side; the other follows. The patched pane keeps every lens locked to its target stripe.Test plan
demos/demo-1.html…demos/demo-5.html) still render correctly — single-lens and absolute-positioned lens cases remain unchanged..liquidGLlenses, every lens refracts the content directly behind it at every scroll position.