Skip to content
Merged
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
2 changes: 1 addition & 1 deletion reflex/.templates/jinja/web/vite.config.js.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ function alwaysUseReactDomServerNode() {
}

export default defineConfig((config) => ({
base: "{{base}}",
plugins: [
alwaysUseReactDomServerNode(),
reactRouter(),
safariCacheBustPlugin(),
],
build: {
assetsDir: "{{base}}assets".slice(1),
rollupOptions: {
jsx: {},
output: {
Expand Down
12 changes: 1 addition & 11 deletions reflex/.templates/web/utils/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -969,17 +969,7 @@ export const useEventLoop = (
useEffect(() => {
if (!sentHydrate.current) {
queueEvents(
initial_events().map((e) => ({
...e,
router_data: {
pathname: location.pathname,
query: {
...Object.fromEntries(searchParams.entries()),
...params.current,
},
asPath: location.pathname + location.search,
},
})),
initial_events(),
socket,
true,
navigate,
Expand Down
2 changes: 1 addition & 1 deletion reflex/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def router(self) -> Callable[[str], str | None]:
"""
from reflex.route import get_router

return get_router(list(self._unevaluated_pages))
return get_router(list(dict.fromkeys([*self._unevaluated_pages, *self._pages])))

def get_load_events(self, path: str) -> list[IndividualEventType[()]]:
"""Get the load events for a route.
Expand Down
4 changes: 4 additions & 0 deletions reflex/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from collections.abc import Callable

from reflex import constants
from reflex.config import get_config


def verify_route_validity(route: str) -> None:
Expand Down Expand Up @@ -211,6 +212,9 @@ def get_route(path: str) -> str | None:
Returns:
The first matching route, or None if no match is found.
"""
config = get_config()
if config.frontend_path:
path = path.removeprefix(config.frontend_path)
path = "/" + path.removeprefix("/").removesuffix("/")
if path == "/index":
path = "/"
Expand Down
2 changes: 1 addition & 1 deletion reflex/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2491,7 +2491,7 @@ def on_load_internal(self) -> list[Event | EventSpec | event.EventCallback] | No
# Cache the app reference for subsequent calls.
if type(self)._app_ref is None:
type(self)._app_ref = app
load_events = app.get_load_events(self.router._page.path)
load_events = app.get_load_events(self.router.url.path)
if not load_events:
self.is_hydrated = True
return None # Fast path for navigation with no on_load events defined.
Expand Down
16 changes: 15 additions & 1 deletion reflex/utils/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import os
import zipfile
from pathlib import Path
from pathlib import Path, PosixPath

from rich.progress import MofNCompleteColumn, Progress, TimeElapsedColumn

from reflex import constants
from reflex.config import get_config
from reflex.utils import console, js_runtimes, path_ops, prerequisites, processes
from reflex.utils.exec import is_in_app_harness

Expand Down Expand Up @@ -205,6 +206,19 @@ def build():
wdir / constants.Dirs.STATIC / "404.html",
)

config = get_config()

if frontend_path := config.frontend_path.strip("/"):
Comment thread
adhami3310 marked this conversation as resolved.
frontend_path = PosixPath(frontend_path)
first_part = frontend_path.parts[0]
for child in list((wdir / constants.Dirs.STATIC).iterdir()):
if child.is_dir() and child.name == first_part:
continue
path_ops.mv(
child,
wdir / constants.Dirs.STATIC / frontend_path / child.name,
)
Comment thread
adhami3310 marked this conversation as resolved.


def setup_frontend(
root: Path,
Expand Down
6 changes: 5 additions & 1 deletion reflex/utils/frontend_skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,12 @@ def update_react_router_config(prerender_routes: bool = False):


def _update_react_router_config(config: Config, prerender_routes: bool = False):
basename = "/" + (config.frontend_path or "").strip("/")
if not basename.endswith("/"):
basename += "/"

react_router_config = {
"basename": "/" + (config.frontend_path or "").removeprefix("/"),
"basename": basename,
"future": {
"unstable_optimizeDeps": True,
},
Expand Down
7 changes: 6 additions & 1 deletion tests/units/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,12 @@ def _event(name, val, **kwargs):
token=kwargs.pop("token", token),
name=name,
router_data=kwargs.pop(
"router_data", {"pathname": "/" + route, "query": {arg_name: val}}
"router_data",
{
"pathname": "/" + route,
"query": {arg_name: val},
"asPath": "/test/something",
},
),
payload=kwargs.pop("payload", {}),
**kwargs,
Expand Down
8 changes: 4 additions & 4 deletions tests/units/test_prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
frontend_path="/test",
),
False,
'export default {"basename": "/test", "future": {"unstable_optimizeDeps": true}, "ssr": false};',
'export default {"basename": "/test/", "future": {"unstable_optimizeDeps": true}, "ssr": false};',
),
(
Config(
Expand All @@ -67,21 +67,21 @@ def test_update_react_router_config(config, export, expected_output):
app_name="test",
frontend_path="",
),
'base: "/",',
'assetsDir: "/assets".slice(1),',
),
(
Config(
app_name="test",
frontend_path="/test",
),
'base: "/test/",',
'assetsDir: "/test/assets".slice(1),',
),
(
Config(
app_name="test",
frontend_path="/test/",
),
'base: "/test/",',
'assetsDir: "/test/assets".slice(1),',
),
],
)
Expand Down
Loading