Skip to content

Commit 0d01de5

Browse files
authored
use sirv with spa fallback (#5711)
* use sirv with spa fallback * don't get rid of 404 * define spa fallback * bruh
1 parent 948b993 commit 0d01de5

File tree

9 files changed

+16
-127
lines changed

9 files changed

+16
-127
lines changed

pyi_hashes.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"reflex/components/core/__init__.pyi": "007170b97e58bdf28b2aee381d91c0c7",
1515
"reflex/components/core/auto_scroll.pyi": "10c4cf71d0d0c1d46a8e1205bd119c11",
1616
"reflex/components/core/banner.pyi": "3c07547afc4f215aefd5e5afa409aa25",
17-
"reflex/components/core/client_side_routing.pyi": "57a7917e993f625c623bcef50b60b804",
1817
"reflex/components/core/clipboard.pyi": "a844eb927d9bc2a43f5e88161b258539",
1918
"reflex/components/core/debounce.pyi": "055da7aa890f44fb4d48bd5978f1a874",
2019
"reflex/components/core/helmet.pyi": "43f8497c8fafe51e29dca1dd535d143a",

reflex/.templates/web/app/routes.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { route } from "@react-router/dev/routes";
22
import { flatRoutes } from "@react-router/fs-routes";
33

44
export default [
5-
route("404", "routes/[404]._index.jsx", { id: "404" }),
65
...(await flatRoutes({
76
ignoredRouteFiles: ["routes/\\[404\\]._index.jsx"],
87
})),

reflex/.templates/web/utils/client_side_routing.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

reflex/app.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@
6767
connection_toaster,
6868
)
6969
from reflex.components.core.breakpoints import set_breakpoints
70-
from reflex.components.core.client_side_routing import (
71-
default_404_page,
72-
wait_for_client_redirect,
73-
)
7470
from reflex.components.core.sticky import sticky
7571
from reflex.components.core.upload import Upload, get_upload_dir
7672
from reflex.components.radix import themes
@@ -775,8 +771,10 @@ def add_page(
775771

776772
if route == constants.Page404.SLUG:
777773
if component is None:
778-
component = default_404_page
779-
component = wait_for_client_redirect(self._generate_component(component))
774+
from reflex.components.el.elements import span
775+
776+
component = span("404: Page not found")
777+
component = self._generate_component(component)
780778
title = title or constants.Page404.TITLE
781779
description = description or constants.Page404.DESCRIPTION
782780
image = image or constants.Page404.IMAGE
@@ -1312,7 +1310,9 @@ def memoized_toast_provider():
13121310
self.head_components,
13131311
html_lang=self.html_lang,
13141312
html_custom_attrs=(
1315-
{**self.html_custom_attrs} if self.html_custom_attrs else {}
1313+
{"suppressHydrationWarning": "true", **self.html_custom_attrs}
1314+
if self.html_custom_attrs
1315+
else {"suppressHydrationWarning": "true"}
13161316
),
13171317
)
13181318
)

reflex/components/core/client_side_routing.py

Lines changed: 0 additions & 70 deletions
This file was deleted.

reflex/constants/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ class ReactRouter(Javascript):
174174
rf"(?:{DEV_FRONTEND_LISTENING_REGEX}|{PROD_FRONTEND_LISTENING_REGEX})(.*)"
175175
)
176176

177+
SPA_FALLBACK = "__spa-fallback.html"
178+
177179

178180
# Color mode variables
179181
class ColorMode(SimpleNamespace):

reflex/constants/installer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class Commands(SimpleNamespace):
106106

107107
DEV = "react-router dev --host"
108108
EXPORT = "react-router build"
109-
PROD = "serve ./build/client"
109+
PROD = "sirv ./build/client --single 404.html --host"
110110

111111
PATH = "package.json"
112112

@@ -127,7 +127,7 @@ def DEPENDENCIES(cls) -> dict[str, str]:
127127
"react-router": cls._react_router_version,
128128
"react-router-dom": cls._react_router_version,
129129
"@react-router/node": cls._react_router_version,
130-
"serve": "14.2.4",
130+
"sirv-cli": "3.0.1",
131131
"react": cls._react_version,
132132
"react-helmet": "6.1.0",
133133
"react-dom": cls._react_version,

reflex/testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ def _run_frontend(self):
10081008
/ reflex.constants.Dirs.STATIC
10091009
)
10101010
error_page_map = {
1011-
404: web_root / "404" / "index.html",
1011+
404: web_root / "404.html",
10121012
}
10131013
with Subdir404TCPServer(
10141014
("", 0),

reflex/utils/build.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ def build():
200200
)
201201
processes.show_progress("Creating Production Build", process, checkpoints)
202202
_duplicate_index_html_to_parent_dir(wdir / constants.Dirs.STATIC)
203+
path_ops.cp(
204+
wdir / constants.Dirs.STATIC / constants.ReactRouter.SPA_FALLBACK,
205+
wdir / constants.Dirs.STATIC / "404.html",
206+
)
203207

204208

205209
def setup_frontend(

0 commit comments

Comments
 (0)