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
@@ -0,0 +1 @@
Add the `REFLEX_REFERRER_PARAM` environment variable, read at compile time to append a `ref` query parameter to the "Built with Reflex" badge link.
4 changes: 4 additions & 0 deletions packages/reflex-base/src/reflex_base/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,10 @@ class EnvironmentVariables:
# Extra plugins to append to the config's plugins list.
REFLEX_EXTRA_PLUGINS: EnvVar[list[type[Plugin]]] = env_var([])

# Referrer identifier appended (urlencoded) to the "Built with Reflex"
# badge link as https://reflex.dev/?ref=<value>. Read at compile time.
REFLEX_REFERRER_PARAM: EnvVar[str | None] = env_var(None)


environment = EnvironmentVariables()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The "Built with Reflex" badge appends a urlencoded `ref` query parameter to its reflex.dev link when the `REFLEX_REFERRER_PARAM` environment variable is set at compile time.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Components for displaying the Reflex sticky logo."""

import urllib.parse

from reflex_base.components.component import ComponentNamespace
from reflex_base.environment import environment
from reflex_base.style import Style

from reflex_components_core.core.colors import color
Expand Down Expand Up @@ -69,6 +72,18 @@ def add_style(self):
})


def _badge_href() -> str:
"""Compute the badge link, appending the referrer param when set.

Returns:
The badge destination URL.
"""
referrer = environment.REFLEX_REFERRER_PARAM.get()

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.

P1 Dependency floor lacks attribute

When production compilation uses the supported minimum dependency set, reflex-base 0.9.7 lacks REFLEX_REFERRER_PARAM, so _badge_href() raises AttributeError while creating the sticky badge and aborts compilation. Please raise the reflex-base minimum to a release containing this new attribute.

Knowledge Base Used: Component package ecosystem

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Require the reflex-base version that defines this variable

When reflex-components-core is installed with its declared minimum reflex-base >= 0.9.7, that released base package does not define REFLEX_REFERRER_PARAM, so compiling a production app with the default sticky badge raises AttributeError here. Raise the dependency floor to the base release containing this field (using the repository's development-pin flow until that release is published) so independently installed core packages remain usable.

AGENTS.md reference: AGENTS.md:L22-L23

Useful? React with 👍 / 👎.

if referrer:
return f"https://reflex.dev/?ref={urllib.parse.quote(referrer, safe='')}"
return "https://reflex.dev"


class StickyBadge(A):
"""A badge that displays the Reflex sticky logo."""

Expand All @@ -82,7 +97,7 @@ def create(cls):
return super().create(
StickyLogo.create(),
desktop_only(StickyLabel.create()),
href="https://reflex.dev",
href=_badge_href(),
target="_blank",
width="auto",
padding="0.375rem",
Expand Down
39 changes: 39 additions & 0 deletions tests/units/components/core/test_sticky.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Tests for the "Built with Reflex" sticky badge."""

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Move the test into the subpackage source mirror

This test covers packages/reflex-components-core/src/reflex_components_core/core/sticky.py, but it was added under tests/units/components/core/; move it to tests/units/reflex_components_core/core/test_sticky.py so the test layout mirrors the subpackage path as required and future module-scoped test selection finds it in the expected location.

AGENTS.md reference: AGENTS.md:L55-L58

Useful? React with 👍 / 👎.


import pytest
from reflex_components_core.core.sticky import StickyBadge


def _badge_href() -> str:
"""Render a fresh badge and extract its href prop.

Returns:
The rendered href value, without surrounding quotes.
"""
props = StickyBadge.create().render()["props"]
href_prop = next(p for p in props if p.startswith("href:"))
return href_prop.removeprefix("href:").strip('"')


def test_badge_href_default(monkeypatch: pytest.MonkeyPatch):
"""Without a referrer param, the badge links to the plain reflex.dev URL."""
monkeypatch.delenv("REFLEX_REFERRER_PARAM", raising=False)
assert _badge_href() == "https://reflex.dev"


def test_badge_href_with_referrer(monkeypatch: pytest.MonkeyPatch):
"""A referrer param is appended as a ref query parameter."""
monkeypatch.setenv("REFLEX_REFERRER_PARAM", "owner-123")
assert _badge_href() == "https://reflex.dev/?ref=owner-123"


def test_badge_href_urlencodes_referrer(monkeypatch: pytest.MonkeyPatch):
"""Special characters in the referrer param are urlencoded."""
monkeypatch.setenv("REFLEX_REFERRER_PARAM", "a b&c/d?e=f")
assert _badge_href() == "https://reflex.dev/?ref=a%20b%26c%2Fd%3Fe%3Df"


def test_badge_href_empty_referrer(monkeypatch: pytest.MonkeyPatch):
"""An empty referrer param falls back to the default URL."""
monkeypatch.setenv("REFLEX_REFERRER_PARAM", "")
assert _badge_href() == "https://reflex.dev"
Loading