فهرست منبع

move some of the config

Khaleel Al-Adhami 2 هفته پیش
والد
کامیت
05b7e4ebe2

+ 0 - 7
reflex/.templates/web/next.config.js

@@ -1,7 +0,0 @@
-module.exports = {
-  basePath: "",
-  compress: true,
-  reactStrictMode: true,
-  trailingSlash: true,
-  output: "",
-};

+ 4 - 2
reflex/constants/base.py

@@ -38,8 +38,10 @@ class Dirs(SimpleNamespace):
     COMPONENTS_PATH = "/".join([UTILS, "components"])
     # The name of the contexts file.
     CONTEXTS_PATH = "/".join([UTILS, "context"])
-    # The name of the output static directory.
-    STATIC = "build/client"
+    # The name of the output directory.
+    BUILD_DIR = "build"
+    # The name of the static files directory.
+    STATIC = BUILD_DIR + "/client"
     # The name of the public html directory served at "/"
     PUBLIC = "public"
     # The directory where styles are located.

+ 9 - 9
reflex/utils/prerequisites.py

@@ -1085,7 +1085,7 @@ def update_next_config(
     """
     next_config_file = get_web_dir() / constants.Next.CONFIG_FILE
 
-    next_config = _update_next_config(
+    next_config = _update_react_router_config(
         get_config(), export=export, transpile_packages=transpile_packages
     )
 
@@ -1096,28 +1096,28 @@ def update_next_config(
         next_config_file.write_text(next_config)
 
 
-def _update_next_config(
+def _update_react_router_config(
     config: Config, export: bool = False, transpile_packages: list[str] | None = None
 ):
-    next_config = {
+    react_router_config = {
         "basePath": config.frontend_path or "",
         "compress": config.next_compression,
         "trailingSlash": True,
         "staticPageGenerationTimeout": config.static_page_generation_timeout,
+        "ssr": False,
     }
     if not config.next_dev_indicators:
-        next_config["devIndicators"] = False
+        react_router_config["devIndicators"] = False
 
     if transpile_packages:
-        next_config["transpilePackages"] = list(
+        react_router_config["transpilePackages"] = list(
             {format_library_name(p) for p in transpile_packages}
         )
     if export:
-        next_config["output"] = "export"
-        next_config["distDir"] = constants.Dirs.STATIC
+        react_router_config["output"] = "export"
+        react_router_config["build"] = constants.Dirs.BUILD_DIR
 
-    next_config_json = re.sub(r'"([^"]+)"(?=:)', r"\1", json.dumps(next_config))
-    return f"module.exports = {next_config_json};"
+    return f"export default {json.dumps(react_router_config)};"
 
 
 def remove_existing_bun_installation():

+ 20 - 3
tests/units/compiler/test_compiler.py

@@ -6,8 +6,11 @@ import pytest
 
 from reflex import constants
 from reflex.compiler import compiler, utils
+from reflex.components.base import document
 from reflex.constants.compiler import PageNames
 from reflex.utils.imports import ImportVar, ParsedImportDict
+from reflex.vars.base import Var
+from reflex.vars.sequence import LiteralStringVar
 
 
 @pytest.mark.parametrize(
@@ -310,9 +313,21 @@ def test_create_document_root():
     assert isinstance(root, utils.Html)
     assert isinstance(root.children[0], utils.Head)
     # Default language.
-    assert root.lang == "en"  # pyright: ignore [reportAttributeAccessIssue]
+    lang = root.lang  # pyright: ignore [reportAttributeAccessIssue]
+    assert isinstance(lang, LiteralStringVar)
+    assert lang.equals(Var.create("en"))
     # No children in head.
-    assert len(root.children[0].children) == 0
+    assert len(root.children[0].children) == 4
+    assert isinstance(root.children[0].children[0], utils.Meta)
+    char_set = root.children[0].children[0].char_set  # pyright: ignore [reportAttributeAccessIssue]
+    assert isinstance(char_set, LiteralStringVar)
+    assert char_set.equals(Var.create("utf-8"))
+    assert isinstance(root.children[0].children[1], utils.Meta)
+    name = root.children[0].children[1].name  # pyright: ignore [reportAttributeAccessIssue]
+    assert isinstance(name, LiteralStringVar)
+    assert name.equals(Var.create("viewport"))
+    assert isinstance(root.children[0].children[2], document.Meta)
+    assert isinstance(root.children[0].children[3], document.Links)
 
     # Test with components.
     comps = [
@@ -327,6 +342,8 @@ def test_create_document_root():
     # Two children in head.
     assert isinstance(root, utils.Html)
     assert len(root.children[0].children) == 2
-    assert root.lang == "rx"  # pyright: ignore [reportAttributeAccessIssue]
+    lang = root.lang  # pyright: ignore [reportAttributeAccessIssue]
+    assert isinstance(lang, LiteralStringVar)
+    assert lang.equals(Var.create("rx"))
     assert isinstance(root.custom_attrs, dict)
     assert root.custom_attrs == {"project": "reflex"}

+ 3 - 3
tests/units/test_prerequisites.py

@@ -12,7 +12,7 @@ from reflex.reflex import cli
 from reflex.testing import chdir
 from reflex.utils.prerequisites import (
     CpuInfo,
-    _update_next_config,
+    _update_react_router_config,
     cached_procedure,
     get_cpu_info,
     rename_imports_and_app_name,
@@ -82,7 +82,7 @@ runner = CliRunner()
     ],
 )
 def test_update_next_config(config, export, expected_output):
-    output = _update_next_config(config, export=export)
+    output = _update_react_router_config(config, export=export)
     assert output == expected_output
 
 
@@ -102,7 +102,7 @@ def test_update_next_config(config, export, expected_output):
     ),
 )
 def test_transpile_packages(transpile_packages, expected_transpile_packages):
-    output = _update_next_config(
+    output = _update_react_router_config(
         Config(app_name="test"),
         transpile_packages=transpile_packages,
     )