Skip to content

Commit 5a51b74

Browse files
committed
fix prevent hook name collision with unique ID
1 parent 6fbd8b1 commit 5a51b74

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

reflex/components/core/auto_scroll.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ def add_hooks(self) -> list[str | Var]:
5252
The hooks required for the component.
5353
"""
5454
ref_name = self.get_ref()
55+
unique_id = ref_name
5556
return [
5657
"const wasNearBottom = useRef(false);",
5758
"const hadScrollbar = useRef(false);",
5859
f"""
59-
const checkIfNearBottom = () => {{
60+
const checkIfNearBottom_{unique_id} = () => {{
6061
if (!{ref_name}.current) return;
6162
6263
const container = {ref_name}.current;
@@ -71,7 +72,7 @@ def add_hooks(self) -> list[str | Var]:
7172
}};
7273
""",
7374
f"""
74-
const scrollToBottomIfNeeded = () => {{
75+
const scrollToBottomIfNeeded_{unique_id} = () => {{
7576
if (!{ref_name}.current) return;
7677
7778
const container = {ref_name}.current;
@@ -93,24 +94,24 @@ def add_hooks(self) -> list[str | Var]:
9394
const container = {ref_name}.current;
9495
if (!container) return;
9596
96-
scrollToBottomIfNeeded();
97+
scrollToBottomIfNeeded_{unique_id}();
9798
9899
// Create ResizeObserver to detect height changes
99100
const resizeObserver = new ResizeObserver(() => {{
100-
scrollToBottomIfNeeded();
101+
scrollToBottomIfNeeded_{unique_id}();
101102
}});
102103
103104
// Track scroll position before height changes
104-
container.addEventListener('scroll', checkIfNearBottom);
105+
container.addEventListener('scroll', checkIfNearBottom_{unique_id});
105106
106107
// Initial check
107-
checkIfNearBottom();
108+
checkIfNearBottom_{unique_id}();
108109
109110
// Observe container for size changes
110111
resizeObserver.observe(container);
111112
112113
return () => {{
113-
container.removeEventListener('scroll', checkIfNearBottom);
114+
container.removeEventListener('scroll', checkIfNearBottom_{unique_id});
114115
resizeObserver.disconnect();
115116
}};
116117
}});

0 commit comments

Comments
 (0)