Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def create(
The component.
"""
id_ = cls.slugify(text)
href = rx.State.router.page.full_path + "#" + id_
href = rx.State.router.page.full_raw_path + "#" + id_
scroll_margin = rx.cond(
HostingBannerState.is_banner_visible,
"scroll-mt-[113px]",
Expand Down
Empty file.
Empty file.
Empty file.
42 changes: 42 additions & 0 deletions tests/units/reflex_ui_shared/components/blocks/test_headings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Unit tests for reflex_ui_shared.components.blocks.headings."""

from reflex_ui_shared.components.blocks.headings import HeadingLink


def _all_rendered_prop_text(component) -> str:
"""Collect the string form of every prop across a component tree.

Args:
component: A Reflex component.

Returns:
A single string containing the concatenated props of the component and
all of its descendants.
"""
texts = [str(component._render().props)]
for child in component.children:
texts.append(_all_rendered_prop_text(child))
return " ".join(texts)
Comment on lines +6 to +19
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing type annotation on component parameter

_all_rendered_prop_text is untyped on its parameter, which pyright will flag and which doesn't match the Google-style docstring convention used elsewhere in the codebase. Adding a type makes it easier to understand what the helper accepts.

Suggested change
def _all_rendered_prop_text(component) -> str:
"""Collect the string form of every prop across a component tree.
Args:
component: A Reflex component.
Returns:
A single string containing the concatenated props of the component and
all of its descendants.
"""
texts = [str(component._render().props)]
for child in component.children:
texts.append(_all_rendered_prop_text(child))
return " ".join(texts)
def _all_rendered_prop_text(component: rx.Component) -> str:

You'll also need import reflex as rx at the top alongside the existing import.



def test_heading_link_uses_full_raw_path():
"""Heading anchor href must preserve the frontend_path prefix.

The HeadingLink anchor's href is built from ``router.page``. Using
``full_path`` loses the ``frontend_path`` prefix because ``path`` is the
registered (normalized) route; ``full_raw_path`` preserves the URL the
client actually requested, which is what a public-facing anchor needs.
"""
component = HeadingLink.create(text="Sample Section", heading="h2")
rendered = _all_rendered_prop_text(component)

assert "full_raw_path" in rendered, (
"heading anchor href should reference router.page.full_raw_path to "
"preserve frontend_path prefix"
)
# "full_path" is a substring of "full_raw_path", so strip matches of the
# correct name before checking for the stale one.
assert "full_path" not in rendered.replace("full_raw_path", ""), (
"heading anchor href still references router.page.full_path; this "
"drops the frontend_path prefix when frontend_path is set"
)
Loading