You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- SEO compatible rendering
- Prerenders the initial component via the template tag using `vdom_to_html`, then loads the actual component in the background within a `hidden` div. When loaded, the prerender is replaced with the actual render.
- `settings.py:REACTPY_PRERENDER` can be set to `True` to enable this behavior by default
- Enable it on individual components via the template tag: `{% component "..." prerender="True" %}`
- Docs styling, verbiage, and formatting tweaks
- Rename undocumented utility function `reactpy_django.utils.ComponentPreloader` to `reactpy_django.utils.RootComponentFinder`.
- Fix JavaScript being via `pip install -e .` on Windows.
- Update PyPi package metadata
- Update pull request template
Copy file name to clipboardExpand all lines: docs/src/reference/settings.md
+26-13
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,11 @@
2
2
3
3
<pclass="intro"markdown>
4
4
5
-
Your **Django project's**`settings.py` can modify the behavior of ReactPy.
5
+
<!--intro-start-->
6
+
7
+
These are ReactPy-Django's default settings values. You can modify these values in your **Django project's**`settings.py` to change the behavior of ReactPy.
8
+
9
+
<!--intro-end-->
6
10
7
11
</p>
8
12
@@ -14,25 +18,34 @@ Your **Django project's** `settings.py` can modify the behavior of ReactPy.
14
18
15
19
---
16
20
17
-
## Primary Configuration
18
-
19
21
<!--config-table-start-->
20
22
21
-
These are ReactPy-Django's default settings values. You can modify these values in your **Django project's**`settings.py` to change the behavior of ReactPy.
23
+
## General Settings
22
24
23
25
| Setting | Default Value | Example Value(s) | Description |
24
26
| --- | --- | --- | --- |
25
-
|`#!python REACTPY_CACHE`|`#!python "default"`|`#!python "my-reactpy-cache"`| Cache used to store ReactPy web modules. ReactPy benefits from a fast, well indexed cache. We recommend installing [`redis`](https://redis.io/) or [`python-diskcache`](https://grantjenks.com/docs/diskcache/tutorial.html#djangocache). |
26
-
|`#!python REACTPY_DATABASE`|`#!python "default"`|`#!python "my-reactpy-database"`| Database used to store ReactPy session data. ReactPy requires a multiprocessing-safe and thread-safe database. If configuring `#!python REACTPY_DATABASE`, it is mandatory to enable our database router like such:<br/>`#!python DATABASE_ROUTERS = ["reactpy_django.database.Router", ...]`|
27
-
|`#!python REACTPY_SESSION_MAX_AGE`|`#!python 259200`|`#!python 0`, `#!python 60`, `#!python 96000`| Maximum seconds to store ReactPy session data, such as `#!python args` and `#!python kwargs` passed into your component template tag. Use `#!python 0` to not store any session data. |
28
-
|`#!python REACTPY_URL_PREFIX`|`#!python "reactpy/"`|`#!python "rp/"`, `#!python "render/reactpy/"`| The prefix to be used for all ReactPy WebSocket and HTTP URLs. |
29
-
|`#!python REACTPY_DEFAULT_QUERY_POSTPROCESSOR`|`#!python "reactpy_django.utils.django_query_postprocessor"`|`#!python None`, `#!python "example_project.my_query_postprocessor"`| Dotted path to the default `#!python reactpy_django.hooks.use_query` postprocessor function. Postprocessor functions can be async or sync, and the parameters must contain the arg `#!python data`. Set `#!python REACTPY_DEFAULT_QUERY_POSTPROCESSOR` to `#!python None` to globally disable the default postprocessor. |
27
+
|`#!python REACTPY_URL_PREFIX`|`#!python "reactpy/"`|`#!python "rp/"`, `#!python "render/reactpy/"`| The prefix used for all ReactPy WebSocket and HTTP URLs. |
28
+
|`#!python REACTPY_DEFAULT_QUERY_POSTPROCESSOR`|`#!python "reactpy_django.utils.django_query_postprocessor"`|`#!python "example_project.postprocessor"`, `#!python None`| Dotted path to the default `#!python reactpy_django.hooks.use_query` postprocessor function. Postprocessor functions can be async or sync, and the function must contain a `#!python data` parameter. Set `#!python REACTPY_DEFAULT_QUERY_POSTPROCESSOR` to `#!python None` to globally disable the default postprocessor. |
30
29
|`#!python REACTPY_AUTH_BACKEND`|`#!python "django.contrib.auth.backends.ModelBackend"`|`#!python "example_project.auth.MyModelBackend"`| Dotted path to the Django authentication backend to use for ReactPy components. This is only needed if:<br/> 1. You are using `#!python AuthMiddlewareStack` and...<br/> 2. You are using Django's `#!python AUTHENTICATION_BACKENDS` setting and...<br/> 3. Your Django user model does not define a `#!python backend` attribute. |
31
-
|`#!python REACTPY_BACKHAUL_THREAD`|`#!python False`|`#!python True`| Whether to render ReactPy components in a dedicated thread. This allows the web server to process traffic during ReactPy rendering. Vastly improves throughput with web servers such as [`hypercorn`](https://pgjones.gitlab.io/hypercorn/) and [`uvicorn`](https://www.uvicorn.org/). |
32
-
|`#!python REACTPY_DEFAULT_HOSTS`|`#!python None`|`#!python ["localhost:8000", "localhost:8001", "localhost:8002/subdir" ]`| The default host(s) that can render your ReactPy components. ReactPy will use these hosts in a round-robin fashion, allowing for easy distributed computing. You can use the `#!python host` argument in your [template tag](../reference/template-tag.md#component) as a manual override. |
33
-
|`#!python REACTPY_RECONNECT_INTERVAL`|`#!python 750`|`#!python 100`, `#!python 2500`, `#!python 6000`| Milliseconds between client reconnection attempts. This value will gradually increase if `#!python REACTPY_RECONNECT_BACKOFF_MULTIPLIER` is greater than `#!python 1`. |
30
+
31
+
## Performance Settings
32
+
33
+
| Setting | Default Value | Example Value(s) | Description |
34
+
| --- | --- | --- | --- |
35
+
|`#!python REACTPY_DATABASE`|`#!python "default"`|`#!python "my-reactpy-database"`| Multiprocessing-safe database used to store ReactPy session data. If configuring `#!python REACTPY_DATABASE`, it is mandatory to enable our database router like such:<br/>`#!python DATABASE_ROUTERS = ["reactpy_django.database.Router", ...]`|
36
+
|`#!python REACTPY_CACHE`|`#!python "default"`|`#!python "my-reactpy-cache"`| Cache used for ReactPy JavaScript modules. We recommend installing [`redis`](https://redis.io/) or [`python-diskcache`](https://grantjenks.com/docs/diskcache/tutorial.html#djangocache). |
37
+
|`#!python REACTPY_BACKHAUL_THREAD`|`#!python False`|`#!python True`| Configures whether ReactPy components are rendered in a dedicated thread. This allows the web server to process traffic during ReactPy rendering. Vastly improves throughput with web servers such as [`hypercorn`](https://pgjones.gitlab.io/hypercorn/) and [`uvicorn`](https://www.uvicorn.org/). |
38
+
|`#!python REACTPY_DEFAULT_HOSTS`|`#!python None`|`#!python ["localhost:8000", "localhost:8001", "localhost:8002/subdir"]`| The default host(s) that can render your ReactPy components. ReactPy will use these hosts in a round-robin fashion, allowing for easy distributed computing. You can use the `#!python host` argument in your [template tag](../reference/template-tag.md#component) as a manual override. |
39
+
|`#!python REACTPY_PRERENDER`|`#!python False`|`#!python True`| Configures whether to pre-render your components, which enables SEO compatibility and increases perceived responsiveness. You can use the `#!python prerender` argument in your [template tag](../reference/template-tag.md#component) as a manual override. During pre-rendering, there are some key differences in behavior:<br/> 1. Only the component's first render is pre-rendered.<br/> 2. All `#!python connection` related hooks use HTTP.<br/> 3. `#!python html.script` is executed during both pre-render and render.<br/> 4. Component is non-interactive until a WebSocket connection is formed. |
40
+
41
+
## Stability Settings
42
+
43
+
| Setting | Default Value | Example Value(s) | Description |
|`#!python REACTPY_RECONNECT_BACKOFF_MULTIPLIER`|`#!python 1.25`|`#!python 1`, `#!python 1.5`, `#!python 3`| On each reconnection attempt, the `#!python REACTPY_RECONNECT_INTERVAL` will be multiplied by this value to increase the time between attempts. You can keep time between each reconnection the same by setting this to `#!python 1`. |
34
47
|`#!python REACTPY_RECONNECT_MAX_INTERVAL`|`#!python 60000`|`#!python 10000`, `#!python 25000`, `#!python 900000`| Maximum milliseconds between client reconnection attempts. This allows setting an upper bound on how high `#!python REACTPY_RECONNECT_BACKOFF_MULTIPLIER` can increase the time between reconnection attempts. |
35
48
|`#!python REACTPY_RECONNECT_MAX_RETRIES`|`#!python 150`|`#!python 0`, `#!python 5`, `#!python 300`| Maximum number of reconnection attempts before the client gives up. |
36
-
|`#!python REACTPY_RECONNECT_BACKOFF_MULTIPLIER`|`#!python 1.25`|`#!python 1`, `#!python 1.5`, `#!python 3`|Multiplier for the time between client reconnection attempts. On each reconnection attempt, the`#!python REACTPY_RECONNECT_INTERVAL` will be multiplied by this to increase the time between attempts. You can keep time between each reconnection the same by setting this to `#!python 1`. |
49
+
|`#!python REACTPY_SESSION_MAX_AGE`|`#!python 259200`|`#!python 0`, `#!python 60`, `#!python 96000`|Maximum seconds to store ReactPy component sessions. This includes data such as`#!python *args` and `#!python **kwargs` passed into your component template tag. Use `#!python 0` to not store any session data. |
Copy file name to clipboardExpand all lines: docs/src/reference/template-tag.md
+8-7
Original file line number
Diff line number
Diff line change
@@ -25,8 +25,9 @@ This template tag can be used to insert any number of ReactPy components onto yo
25
25
| `#!python dotted_path` | `#!python str` | The dotted path to the component to render. | N/A |
26
26
| `#!python *args` | `#!python Any` | The positional arguments to provide to the component. | N/A |
27
27
| `#!python class` | `#!python str | None` | The HTML class to apply to the top-level component div. | `#!python None` |
28
-
| `#!python key` | `#!python str | None` | Force the component's root node to use a [specific key value](https://reactpy.dev/docs/guides/creating-interfaces/rendering-data/index.html#organizing-items-with-keys). Using `#!python key` within a template tag is effectively useless. | `#!python None` |
29
-
| `#!python host` | `#!python str | None` | The host to use for the ReactPy connections. If set to `#!python None`, the host will be automatically configured.<br/>Example values include: `localhost:8000`, `example.com`, `example.com/subdir` | `#!python None` |
28
+
| `#!python key` | `#!python Any` | Force the component's root node to use a [specific key value](https://reactpy.dev/docs/guides/creating-interfaces/rendering-data/index.html#organizing-items-with-keys). Using `#!python key` within a template tag is effectively useless. | `#!python None` |
29
+
| `#!python host` | `#!python str | None` | The host to use for the ReactPy connections. If unset, the host will be automatically configured.<br/>Example values include: `localhost:8000`, `example.com`, `example.com/subdir` | `#!python None` |
30
+
| `#!python prerender` | `#!python str` | If `#!python "True"`, the component will pre-rendered, which enables SEO compatibility and increases perceived responsiveness. | `#!python "False"` |
30
31
| `#!python **kwargs` | `#!python Any` | The keyword arguments to provide to the component. | N/A |
31
32
32
33
<font size="4">**Returns**</font>
@@ -37,11 +38,11 @@ This template tag can be used to insert any number of ReactPy components onto yo
37
38
38
39
<!--context-start-->
39
40
40
-
??? warning "Do not use context variables for the ReactPy component name"
41
+
??? warning "Do not use context variables for the component path"
41
42
42
-
Our preprocessor relies on the template tag containing a string.
43
+
The ReactPy component finder (`#!python reactpy_django.utils.RootComponentFinder`) requires that your component path is a string.
43
44
44
-
**Do not** use Django template/context variables for the component path. Failure to follow this warning can result in unexpected behavior.
45
+
**Do not** use Django template/context variables for the component path. Failure to follow this warning can result in unexpected behavior, such as components that will not render.
45
46
46
47
For example, **do not** do the following:
47
48
@@ -52,7 +53,7 @@ This template tag can be used to insert any number of ReactPy components onto yo
@@ -81,7 +82,7 @@ This template tag can be used to insert any number of ReactPy components onto yo
81
82
82
83
1. If your host address are completely separate ( `origin1.com != origin2.com` ) you will need to [configure CORS headers](https://pypi.org/project/django-cors-headers/) on your main application during deployment.
83
84
2. You will not need to register ReactPy HTTP or WebSocket paths on any applications that do not perform any component rendering.
84
-
3. Your component will only be able to access `#!python *args`/`#!python **kwargs` you provide to the template tag if your applications share a common database.
85
+
3. Your component will only be able to access your template tag's `#!python *args`/`#!python **kwargs` if your applications share a common database.
0 commit comments