MCPcopy Create free account
hub / github.com/dailydotdev/apps / tick

Function tick

packages/shared/src/hooks/comments/useScrollToHashComment.ts:86–133  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

84 };
85
86 const tick = () => {
87 if (performance.now() >= deadline) {
88 stop();
89 return;
90 }
91
92 const element = commentRef.current;
93 if (element && containerRef.current?.contains(element)) {
94 if (target !== element) {
95 target = element;
96 scrollParent = getScrollParent(element);
97 anchor = undefined;
98 }
99
100 const position = measure(element);
101 const previousPosition = anchor;
102 if (
103 !previousPosition ||
104 position.some(
105 (value, index) =>
106 Math.abs(value - previousPosition[index]) > POSITION_TOLERANCE,
107 )
108 ) {
109 element.scrollIntoView({
110 behavior: 'instant',
111 block: 'center',
112 inline: 'nearest',
113 });
114 anchor = measure(element);
115 stableFrames = 0;
116 } else {
117 stableFrames += 1;
118 }
119
120 if (
121 stableFrames >= STABLE_FRAMES &&
122 performance.now() - startedAt >= MIN_SETTLE_MS
123 ) {
124 stop();
125 return;
126 }
127 } else {
128 anchor = undefined;
129 stableFrames = 0;
130 }
131
132 frame = requestAnimationFrame(tick);
133 };
134
135 window.addEventListener('wheel', stop, { passive: true });
136 window.addEventListener('touchmove', stop, { passive: true });

Callers

nothing calls this directly

Calls 4

getScrollParentFunction · 0.85
nowMethod · 0.80
stopFunction · 0.70
measureFunction · 0.70

Tested by

no test coverage detected