Skip to content

Commit 1c93f43

Browse files
authored
Merge branch 'main' into devin/1745800734-add-serialization-docs
2 parents 16a94af + c2bbe47 commit 1c93f43

File tree

6 files changed

+184
-27
lines changed

6 files changed

+184
-27
lines changed

docs/api-reference/cli.md

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,21 @@ Usage: reflex [OPTIONS] COMMAND [ARGS]...
1212
Reflex CLI to create, run, and deploy apps.
1313

1414
Options:
15-
-v, --version Get the Reflex version.
16-
--help Show this message and exit.
15+
--version Show the version and exit.
16+
--help Show this message and exit.
1717

1818
Commands:
19-
db Subcommands for managing the database schema.
20-
demo Run the demo app.
21-
deploy Deploy the app to the Reflex hosting service.
22-
deployments Subcommands for managing the Deployments.
23-
export Export the app to a zip file.
24-
init Initialize a new Reflex app in the current directory.
25-
login Authenticate with Reflex hosting service.
26-
logout Log out of access to Reflex hosting service.
27-
run Run the app in the current directory.
19+
cloud The Hosting CLI.
20+
component CLI for creating custom components.
21+
db Subcommands for managing the database schema.
22+
deploy Deploy the app to the Reflex hosting service.
23+
export Export the app to a zip file.
24+
init Initialize a new Reflex app in the current directory.
25+
login Authenticate with experimental Reflex hosting service.
26+
logout Log out of access to Reflex hosting service.
27+
rename Rename the app in the current directory.
28+
run Run the app in the current directory.
29+
script Subcommands for running helper scripts.
2830
```
2931

3032
## Init
@@ -88,3 +90,39 @@ You can export your app's frontend and backend to zip files using the `reflex ex
8890
The frontend is a compiled NextJS app, which can be deployed to a static hosting service like Github Pages or Vercel.
8991
However this is just a static build, so you will need to deploy the backend separately.
9092
See the self-hosting guide for more information.
93+
94+
## Rename
95+
96+
The `reflex rename` command allows you to rename your Reflex app. This updates the app name in the configuration files.
97+
98+
```bash
99+
$ reflex rename --help
100+
Usage: reflex rename [OPTIONS] NEW_NAME
101+
102+
Rename the app in the current directory.
103+
104+
Options:
105+
--loglevel [debug|default|info|warning|error|critical]
106+
The log level to use.
107+
--help Show this message and exit.
108+
```
109+
110+
## Cloud
111+
112+
The `reflex cloud` command provides access to the Reflex Cloud hosting service. It includes subcommands for managing apps, projects, secrets, and more.
113+
114+
For detailed documentation on Reflex Cloud and deployment, see the [Cloud Quick Start Guide](https://reflex.dev/docs/hosting/deploy-quick-start/).
115+
116+
## Script
117+
118+
The `reflex script` command provides access to helper scripts for Reflex development.
119+
120+
```bash
121+
$ reflex script --help
122+
Usage: reflex script [OPTIONS] COMMAND [ARGS]...
123+
124+
Subcommands for running helper scripts.
125+
126+
Options:
127+
--help Show this message and exit.
128+
```

docs/api-reference/event_triggers.md

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from datetime import datetime
44
import reflex as rx
55

66
from pcweb.templates.docpage import docdemo, h1_comp, text_comp, docpage
7+
from pcweb.pages.docs import events
78

89
SYNTHETIC_EVENTS = [
910
{
@@ -92,27 +93,70 @@ SYNTHETIC_EVENTS = [
9293
},
9394
{
9495
"name": "on_mount",
95-
"description": "The on_mount event handler is called after the component is rendered on the page. It is similar to a page on_load event, although it does not necessarily fire when navigating between pages.",
96+
"description": "The on_mount event handler is called after the component is rendered on the page. It is similar to a page on_load event, although it does not necessarily fire when navigating between pages. This event is particularly useful for initializing data, making API calls, or setting up component-specific state when a component first appears.",
9697
"state": """class MountState(rx.State):
9798
events: list[str] = []
99+
data: list[dict] = []
100+
loading: bool = False
98101
99102
@rx.event
100103
def on_mount(self):
101104
self.events = self.events[-4:] + ["on_mount @ " + str(datetime.now())]
105+
106+
@rx.event
107+
async def load_data(self):
108+
# Common pattern: Set loading state, yield to update UI, then fetch data
109+
self.loading = True
110+
yield
111+
# Simulate API call
112+
import asyncio
113+
await asyncio.sleep(1)
114+
self.data = [dict(id=1, name="Item 1"), dict(id=2, name="Item 2")]
115+
self.loading = False
102116
""",
103-
"example": """rx.vstack(rx.foreach(MountState.events, rx.text), on_mount=MountState.on_mount)""",
117+
"example": """rx.vstack(
118+
rx.heading("Component Lifecycle Demo"),
119+
rx.foreach(MountState.events, rx.text),
120+
rx.cond(
121+
MountState.loading,
122+
rx.spinner(),
123+
rx.foreach(
124+
MountState.data,
125+
lambda item: rx.text(f"ID: {item['id']} - {item['name']}")
126+
)
127+
),
128+
on_mount=MountState.on_mount,
129+
)""",
104130
},
105131
{
106132
"name": "on_unmount",
107-
"description": "The on_unmount event handler is called after removing the component from the page. However, on_unmount will only be called for internal navigation, not when following external links or refreshing the page.",
133+
"description": "The on_unmount event handler is called after removing the component from the page. However, on_unmount will only be called for internal navigation, not when following external links or refreshing the page. This event is useful for cleaning up resources, saving state, or performing cleanup operations before a component is removed from the DOM.",
108134
"state": """class UnmountState(rx.State):
109135
events: list[str] = []
136+
resource_id: str = "resource-12345"
137+
status: str = "Resource active"
110138
111139
@rx.event
112140
def on_unmount(self):
113141
self.events = self.events[-4:] + ["on_unmount @ " + str(datetime.now())]
142+
# Common pattern: Clean up resources when component is removed
143+
self.status = f"Resource {self.resource_id} cleaned up"
144+
145+
@rx.event
146+
def initialize_resource(self):
147+
self.status = f"Resource {self.resource_id} initialized"
114148
""",
115-
"example": """rx.vstack(rx.foreach(UnmountState.events, rx.text), on_unmount=UnmountState.on_unmount)""",
149+
"example": """rx.vstack(
150+
rx.heading("Unmount Demo"),
151+
rx.foreach(UnmountState.events, rx.text),
152+
rx.text(UnmountState.status),
153+
rx.link(
154+
rx.button("Navigate Away (Triggers Unmount)"),
155+
href="/docs",
156+
),
157+
on_mount=UnmountState.initialize_resource,
158+
on_unmount=UnmountState.on_unmount,
159+
)""",
116160
},
117161
{
118162
"name": "on_mouse_up",
@@ -270,6 +314,70 @@ These events are triggered by event triggers.
270314

271315
Event triggers are component specific and are listed in the documentation for each component.
272316

317+
## Component Lifecycle Events
318+
319+
Reflex components have lifecycle events like `on_mount` and `on_unmount` that allow you to execute code at specific points in a component's existence. These events are crucial for initializing data, cleaning up resources, and creating dynamic user interfaces.
320+
321+
### When Lifecycle Events Are Activated
322+
323+
- **on_mount**: This event is triggered immediately after a component is rendered and attached to the DOM. It fires:
324+
- When a page containing the component is first loaded
325+
- When a component is conditionally rendered (appears after being hidden)
326+
- When navigating to a page containing the component using internal navigation
327+
- It does NOT fire when the page is refreshed or when following external links
328+
329+
- **on_unmount**: This event is triggered just before a component is removed from the DOM. It fires:
330+
- When navigating away from a page containing the component using internal navigation
331+
- When a component is conditionally removed from the DOM (e.g., via a condition that hides it)
332+
- It does NOT fire when refreshing the page, closing the browser tab, or following external links
333+
334+
## Page Load Events
335+
336+
In addition to component lifecycle events, Reflex also provides page-level events like `on_load` that are triggered when a page loads. The `on_load` event is useful for:
337+
338+
- Fetching data when a page first loads
339+
- Checking authentication status
340+
- Initializing page-specific state
341+
- Setting default values for cookies or browser storage
342+
343+
You can specify an event handler to run when the page loads using the `on_load` parameter in the `@rx.page` decorator or `app.add_page()` method:
344+
345+
```python
346+
class State(rx.State):
347+
data: dict = dict()
348+
349+
@rx.event
350+
def get_data(self):
351+
# Fetch data when the page loads
352+
self.data = fetch_data()
353+
354+
@rx.page(on_load=State.get_data)
355+
def index():
356+
return rx.text('Data loaded on page load')
357+
```
358+
359+
This is particularly useful for authentication checks:
360+
361+
```python
362+
class State(rx.State):
363+
authenticated: bool = False
364+
365+
@rx.event
366+
def check_auth(self):
367+
# Check if user is authenticated
368+
self.authenticated = check_auth()
369+
if not self.authenticated:
370+
return rx.redirect('/login')
371+
372+
@rx.page(on_load=State.check_auth)
373+
def protected_page():
374+
return rx.text('Protected content')
375+
```
376+
377+
For more details on page load events, see the [page load events documentation]({events.page_load_events.path}).
378+
379+
# Event Reference
380+
273381
```python eval
274382
rx.box(
275383
rx.divider(),

docs/hosting/deploy-quick-start.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ The command is by default interactive. It asks you a few questions for informati
6363

6464
That’s it! You should receive some feedback on the progress of your deployment and in a few minutes your app should be up. 🎉
6565

66+
For detailed information about the deploy command and its options, see the [Deploy API Reference](https://reflex.dev/docs/hosting/deploy/) and the [CLI Reference](https://reflex.dev/docs/api-reference/cli/).
67+
68+
6669
```md alert info
6770
# Once your code is uploaded, the hosting service will start the deployment. After a complete upload, exiting from the command **does not** affect the deployment process. The command prints a message when you can safely close it without affecting the deployment.
6871
```
@@ -83,4 +86,4 @@ To go back, i.e. from an app to a project or from a project to your list of proj
8386
```md alert info
8487
# All flag values are saved between runs
8588
All your flag values, i.e. environment variables or regions or tokens, are saved between runs. This means that if you run a command and you pass a flag value, the next time you run the same command the flag value will be the same as the last time you ran it. This means you should only set the flag values again if you want to change them.
86-
```
89+
```

docs/wrapping-react/overview.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ We also have a var `color` which is the current color of the color picker.
5959
Since this component has interaction we must specify any event triggers that the component takes. The color picker has a single trigger `on_change` to specify when the color changes. This trigger takes in a single argument `color` which is the new color.
6060

6161
```python exec
62-
class ColorPicker(rx.Component):
62+
from reflex.components.component import NoSSRComponent
63+
64+
class ColorPicker(NoSSRComponent):
6365
library = "react-colorful"
6466
tag = "HexColorPicker"
6567
color: rx.Var[str]
@@ -87,7 +89,9 @@ rx.box(
8789
```
8890

8991
```python
90-
class ColorPicker(rx.Component):
92+
from reflex.components.component import NoSSRComponent
93+
94+
class ColorPicker(NoSSRComponent):
9195
library = "react-colorful"
9296
tag = "HexColorPicker"
9397
color: rx.Var[str]
@@ -147,4 +151,4 @@ export default function App() {
147151

148152

149153

150-
In the next page, we will go step by step through a more complex example of wrapping a React component.
154+
In the next page, we will go step by step through a more complex example of wrapping a React component.

pcweb/components/hosting_banner.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,33 @@ def hosting_banner() -> rx.Component:
2727
rx.link(
2828
rx.box(
2929
rx.box(
30+
# Header text with responsive spans
3031
rx.text(
31-
"Reflex Build - ",
32+
"Reflex Build – ",
33+
# Descriptive text: hidden on small, inline on md+
3234
rx.el.span(
3335
"Build internal apps with AI.",
34-
# class_name="text-slate-12 font-medium text-sm",
3536
class_name="hidden md:inline-block text-slate-12 font-medium text-sm",
3637
),
37-
# ... keep this for mobile view if/when needed
38+
# Mobile CTA: inline on small, hidden on md+
3839
rx.el.span(
3940
"Try for Free!",
40-
# class_name="text-slate-12 font-medium text-sm",
4141
class_name="inline-block md:hidden text-slate-12 font-medium text-sm",
4242
),
4343
class_name="text-slate-12 font-semibold text-sm z-[1]",
4444
),
45-
# ... keep this for mobile view if/when needed
45+
# Standalone CTA button: hidden on small, inline on md+
4646
rx.el.button(
4747
"Try for Free!",
48-
class_name="hidden md:inline-block text-green-11 h-[1.5rem] rounded-md bg-green-4 px-1.5 text-sm font-semibold z-[1] items-center justify-center shrink-0",
48+
class_name=(
49+
"hidden md:inline-block "
50+
"text-green-11 h-[1.5rem] rounded-md bg-green-4 "
51+
"px-1.5 text-sm font-semibold z-[1] items-center "
52+
"justify-center shrink-0"
53+
),
4954
),
5055
class_name="flex items-center gap-4",
51-
),
56+
)
5257
),
5358
glow(),
5459
href=REFLEX_AI_BUILDER,

pcweb/whitelist.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
WHITELISTED_PAGES = []
1414

15-
1615
def _check_whitelisted_path(path: str):
1716
if len(WHITELISTED_PAGES) == 0:
1817
return True

0 commit comments

Comments
 (0)