litestar-vite 0.2.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of litestar-vite might be problematic. Click here for more details.

Files changed (121) hide show
  1. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/PKG-INFO +2 -2
  2. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/config.py +4 -3
  3. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/inertia/_utils.py +1 -0
  4. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/inertia/exception_handler.py +20 -12
  5. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/inertia/middleware.py +1 -5
  6. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/inertia/request.py +5 -0
  7. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/inertia/response.py +12 -5
  8. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/pdm.lock +17 -17
  9. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/pyproject.toml +2 -2
  10. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/.github/CODEOWNERS +0 -0
  11. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/.github/dependabot.yaml +0 -0
  12. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/.github/workflows/cd.yaml +0 -0
  13. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/.github/workflows/ci.yaml +0 -0
  14. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/.github/workflows/docs-preview.yaml +0 -0
  15. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/.github/workflows/docs.yaml +0 -0
  16. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/.github/workflows/pr-title.yaml +0 -0
  17. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/.github/workflows/publish.yaml +0 -0
  18. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/.gitignore +0 -0
  19. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/.pre-commit-config.yaml +0 -0
  20. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/.python-version +0 -0
  21. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/CONTRIBUTING.rst +0 -0
  22. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/LICENSE +0 -0
  23. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/Makefile +0 -0
  24. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/README.md +0 -0
  25. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/docs/Makefile +0 -0
  26. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/docs/conf.py +0 -0
  27. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/docs/contribution-guide.rst +0 -0
  28. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/docs/fix_missing_references.py +0 -0
  29. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/docs/index.rst +0 -0
  30. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/docs/reference/config.rst +0 -0
  31. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/docs/reference/plugin.rst +0 -0
  32. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/docs/usage/index.rst +0 -0
  33. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/docs/usage/placeholder.rst +0 -0
  34. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/__init__.py +0 -0
  35. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/basic/app.py +0 -0
  36. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/basic/package-lock.json +0 -0
  37. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/basic/package.json +0 -0
  38. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/basic/public/assets/main-l0sNRNKZ.js +0 -0
  39. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/basic/public/assets/styles-l0sNRNKZ.js +0 -0
  40. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/basic/public/manifest.json +0 -0
  41. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/basic/resources/main.ts +0 -0
  42. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/basic/resources/styles.css +0 -0
  43. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/basic/templates/index.html.j2 +0 -0
  44. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/basic/tsconfig.json +0 -0
  45. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/basic/vite.config.ts +0 -0
  46. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/flash/app.py +0 -0
  47. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/flash/package-lock.json +0 -0
  48. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/flash/package.json +0 -0
  49. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/flash/public/assets/main-l0sNRNKZ.js +0 -0
  50. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/flash/public/assets/styles-l0sNRNKZ.js +0 -0
  51. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/flash/public/manifest.json +0 -0
  52. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/flash/resources/main.ts +0 -0
  53. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/flash/resources/styles.css +0 -0
  54. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/flash/templates/index.html.j2 +0 -0
  55. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/flash/tsconfig.json +0 -0
  56. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/flash/vite.config.ts +0 -0
  57. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/app.py +0 -0
  58. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/package-lock.json +0 -0
  59. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/package.json +0 -0
  60. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/postcss.config.cjs +0 -0
  61. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/public/assets/main-BIhkjqcE.js +0 -0
  62. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/public/assets/styles-B8hX6ha2.css +0 -0
  63. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/public/manifest.json +0 -0
  64. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/resources/Layout.vue +0 -0
  65. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/resources/main.js +0 -0
  66. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/resources/pages/Dashboard.vue +0 -0
  67. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/resources/pages/Home.vue +0 -0
  68. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/resources/styles.css +0 -0
  69. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/resources/templates/index.html +0 -0
  70. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/resources/vite-env.d.ts +0 -0
  71. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/tailwind.config.cjs +0 -0
  72. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/tsconfig.json +0 -0
  73. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/examples/inertia/vite.config.ts +0 -0
  74. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/__init__.py +0 -0
  75. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/__metadata__.py +0 -0
  76. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/cli.py +0 -0
  77. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/commands.py +0 -0
  78. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/inertia/__init__.py +0 -0
  79. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/inertia/config.py +0 -0
  80. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/inertia/plugin.py +0 -0
  81. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/inertia/routes.py +0 -0
  82. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/inertia/types.py +0 -0
  83. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/loader.py +0 -0
  84. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/plugin.py +0 -0
  85. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/py.typed +0 -0
  86. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/template_engine.py +0 -0
  87. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/templates/__init__.py +0 -0
  88. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/templates/index.html.j2 +0 -0
  89. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/templates/main.ts.j2 +0 -0
  90. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/templates/package.json.j2 +0 -0
  91. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/templates/styles.css.j2 +0 -0
  92. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/templates/tsconfig.json.j2 +0 -0
  93. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/litestar_vite/templates/vite.config.ts.j2 +0 -0
  94. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/__init__.py +0 -0
  95. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/conftest.py +0 -0
  96. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/templates/__init__.py +0 -0
  97. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/templates/index.html.j2 +0 -0
  98. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_app/__init__.py +0 -0
  99. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_app/app.py +0 -0
  100. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_app/web/__init__.py +0 -0
  101. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_app/web/public/.gitkeep +0 -0
  102. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_app/web/public/assets/main-l0sNRNKZ.js +0 -0
  103. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_app/web/public/assets/styles-l0sNRNKZ.js +0 -0
  104. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_app/web/public/manifest.json +0 -0
  105. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_app/web/resources/.gitkeep +0 -0
  106. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_app/web/resources/main.ts +0 -0
  107. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_app/web/resources/styles.css +0 -0
  108. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_app/web/templates/.gitkeep +0 -0
  109. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_app/web/templates/index.html +0 -0
  110. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_cli/__init__.py +0 -0
  111. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_cli/conftest.py +0 -0
  112. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_cli/test_init.py +0 -0
  113. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_commands.py +0 -0
  114. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_config.py +0 -0
  115. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_inertia/__init__.py +0 -0
  116. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_inertia/conftest.py +0 -0
  117. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_inertia/templates/index.html.j2 +0 -0
  118. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_inertia/test_inertia_request.py +0 -0
  119. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_inertia/test_inertia_response.py +0 -0
  120. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_inertia/test_routes.py +0 -0
  121. {litestar_vite-0.2.0 → litestar_vite-0.2.2}/tests/test_template_engine.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: litestar-vite
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Vite plugin for Litestar
5
5
  Project-URL: Changelog, https://cofin.github.io/litestar-vite/latest/changelog
6
6
  Project-URL: Discord, https://discord.gg/X3FJqy8d2j
@@ -30,7 +30,7 @@ Classifier: Topic :: Database :: Database Engines/Servers
30
30
  Classifier: Topic :: Software Development
31
31
  Classifier: Typing :: Typed
32
32
  Requires-Python: >=3.8
33
- Requires-Dist: litestar[jinja]>=2.4.0
33
+ Requires-Dist: litestar[jinja]>=2.7.0
34
34
  Provides-Extra: nodeenv
35
35
  Requires-Dist: nodeenv; extra == 'nodeenv'
36
36
  Description-Content-Type: text/markdown
@@ -17,6 +17,7 @@ if TYPE_CHECKING:
17
17
 
18
18
  __all__ = ("ViteConfig", "ViteTemplateConfig")
19
19
  EngineType = TypeVar("EngineType", bound=TemplateEngineProtocol[Any, Any])
20
+ TRUE_VALUES = {"True", "true", "1", "yes", "Y", "T"}
20
21
 
21
22
 
22
23
  @dataclass
@@ -53,7 +54,7 @@ class ViteConfig:
53
54
  This file contains a single line containing the host, protocol, and port the Vite server is running.
54
55
  """
55
56
  hot_reload: bool = field(
56
- default_factory=lambda: os.getenv("VITE_HOT_RELOAD", "True") in {"True", "1", "yes", "Y", "T"},
57
+ default_factory=lambda: os.getenv("VITE_HOT_RELOAD", "True") in TRUE_VALUES,
57
58
  )
58
59
  """Enable HMR for Vite development server."""
59
60
  ssr_enabled: bool = False
@@ -88,11 +89,11 @@ class ViteConfig:
88
89
  install_command: list[str] = field(default_factory=lambda: ["npm", "install"])
89
90
  """Default command to use for installing Vite."""
90
91
  use_server_lifespan: bool = field(
91
- default_factory=lambda: os.getenv("VITE_USE_SERVER_LIFESPAN", "False") in {"True", "1", "yes", "Y", "T"},
92
+ default_factory=lambda: os.getenv("VITE_USE_SERVER_LIFESPAN", "False") in TRUE_VALUES,
92
93
  )
93
94
  """Utilize the server lifespan hook to run Vite."""
94
95
  dev_mode: bool = field(
95
- default_factory=lambda: os.getenv("VITE_DEV_MODE", "False") in {"True", "1", "yes", "Y", "T"},
96
+ default_factory=lambda: os.getenv("VITE_DEV_MODE", "False") in TRUE_VALUES,
96
97
  )
97
98
  """When True, Vite will run with HMR or watch build"""
98
99
  detect_nodeenv: bool = True
@@ -15,6 +15,7 @@ class InertiaHeaders(str, Enum):
15
15
  PARTIAL_DATA = "X-Inertia-Partial-Data"
16
16
  PARTIAL_COMPONENT = "X-Inertia-Partial-Component"
17
17
  LOCATION = "X-Inertia-Location"
18
+ REFERER = "Referer"
18
19
 
19
20
 
20
21
  def get_enabled_header(enabled: bool = True) -> dict[str, Any]:
@@ -1,3 +1,4 @@
1
+ import contextlib
1
2
  import re
2
3
  from typing import TYPE_CHECKING, Any, cast
3
4
 
@@ -7,6 +8,7 @@ from litestar.connection.base import AuthT, StateT, UserT
7
8
  from litestar.exceptions import (
8
9
  HTTPException,
9
10
  InternalServerException,
11
+ NotAuthorizedException,
10
12
  NotFoundException,
11
13
  PermissionDeniedException,
12
14
  )
@@ -42,7 +44,7 @@ class _HTTPConflictException(HTTPException):
42
44
  status_code = HTTP_409_CONFLICT
43
45
 
44
46
 
45
- def exception_to_http_response(request: Request[UserT, AuthT, StateT], exc: Exception) -> Response[Any]:
47
+ def exception_to_http_response(request: Request[UserT, AuthT, StateT], exc: Exception) -> Response[Any]: # noqa: PLR0911
46
48
  """Handler for all exceptions subclassed from HTTPException."""
47
49
  inertia_enabled = getattr(request, "inertia_enabled", False) or getattr(request, "is_inertia", False)
48
50
  if isinstance(exc, NotFoundError):
@@ -64,7 +66,8 @@ def exception_to_http_response(request: Request[UserT, AuthT, StateT], exc: Exce
64
66
  inertia_plugin = cast("InertiaPlugin", request.app.plugins.get("InertiaPlugin"))
65
67
  if extras:
66
68
  content.update({"extra": extras})
67
- flash(request, detail, category="error")
69
+ with contextlib.suppress(Exception):
70
+ flash(request, detail, category="error")
68
71
  if extras and len(extras) >= 1:
69
72
  message = extras[0]
70
73
  default_field = f"root.{message.get('key')}" if message.get("key", None) is not None else "root" # type: ignore
@@ -72,18 +75,23 @@ def exception_to_http_response(request: Request[UserT, AuthT, StateT], exc: Exce
72
75
  match = FIELD_ERR_RE.search(error_detail)
73
76
  field = match.group(1) if match else default_field
74
77
  if isinstance(message, dict):
75
- error(request, field, error_detail)
76
- if status_code in {HTTP_422_UNPROCESSABLE_ENTITY, HTTP_400_BAD_REQUEST}:
77
- return InertiaBack(request)
78
- if (
79
- status_code == HTTP_401_UNAUTHORIZED
80
- and inertia_plugin.config.redirect_unauthorized_to is not None
81
- and not request.url.path.startswith(inertia_plugin.config.redirect_unauthorized_to)
78
+ with contextlib.suppress(Exception):
79
+ error(request, field, error_detail)
80
+ if status_code in {HTTP_422_UNPROCESSABLE_ENTITY, HTTP_400_BAD_REQUEST} or isinstance(
81
+ exc,
82
+ PermissionDeniedException,
82
83
  ):
83
- return InertiaRedirect(
84
- request,
85
- redirect_to=inertia_plugin.config.redirect_unauthorized_to,
84
+ return InertiaBack(request)
85
+ if isinstance(exc, PermissionDeniedException):
86
+ return InertiaBack(request)
87
+ if status_code == HTTP_401_UNAUTHORIZED or isinstance(exc, NotAuthorizedException):
88
+ redirect_to = (
89
+ inertia_plugin.config.redirect_unauthorized_to is not None
90
+ and str(request.url) != inertia_plugin.config.redirect_unauthorized_to
86
91
  )
92
+ if redirect_to:
93
+ return InertiaRedirect(request, redirect_to=cast("str", inertia_plugin.config.redirect_unauthorized_to))
94
+ return InertiaBack(request)
87
95
  return InertiaResponse[Any](
88
96
  media_type=preferred_type,
89
97
  content=content,
@@ -15,7 +15,7 @@ if TYPE_CHECKING:
15
15
  StateT,
16
16
  UserT,
17
17
  )
18
- from litestar.types import ASGIApp
18
+ from litestar.types import ASGIApp, Receive, Scope, Send
19
19
 
20
20
 
21
21
  async def redirect_on_asset_version_mismatch(request: Request[UserT, AuthT, StateT]) -> InertiaRedirect | None:
@@ -32,10 +32,6 @@ async def redirect_on_asset_version_mismatch(request: Request[UserT, AuthT, Stat
32
32
  return InertiaRedirect(request, redirect_to=str(request.url))
33
33
 
34
34
 
35
- if TYPE_CHECKING:
36
- from litestar.types import Receive, Scope, Send
37
-
38
-
39
35
  class InertiaMiddleware(AbstractMiddleware):
40
36
  def __init__(self, app: ASGIApp) -> None:
41
37
  super().__init__(app)
@@ -69,6 +69,11 @@ class InertiaDetails:
69
69
  """Partial Data Reload."""
70
70
  return self._get_header_value(InertiaHeaders.PARTIAL_DATA)
71
71
 
72
+ @cached_property
73
+ def referer(self) -> str | None:
74
+ """Partial Data Reload."""
75
+ return self._get_header_value(InertiaHeaders.REFERER)
76
+
72
77
  @cached_property
73
78
  def is_partial_render(self) -> bool:
74
79
  """Is Partial Data Reload."""
@@ -6,7 +6,7 @@ from functools import lru_cache
6
6
  from mimetypes import guess_type
7
7
  from pathlib import PurePath
8
8
  from textwrap import dedent
9
- from typing import TYPE_CHECKING, Any, Dict, Iterable, Mapping, TypeVar, cast
9
+ from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Mapping, TypeVar, cast
10
10
  from urllib.parse import quote
11
11
 
12
12
  from litestar import Litestar, MediaType, Request, Response
@@ -16,6 +16,7 @@ from litestar.response import Redirect
16
16
  from litestar.response.base import ASGIResponse
17
17
  from litestar.serialization import get_serializer
18
18
  from litestar.status_codes import HTTP_200_OK, HTTP_303_SEE_OTHER, HTTP_307_TEMPORARY_REDIRECT, HTTP_409_CONFLICT
19
+ from litestar.types import Empty
19
20
  from litestar.utils.deprecation import warn_deprecation
20
21
  from litestar.utils.empty import value_or_default
21
22
  from litestar.utils.helpers import get_enum_string_value
@@ -33,6 +34,7 @@ if TYPE_CHECKING:
33
34
  from litestar.connection.base import AuthT, StateT, UserT
34
35
  from litestar.types import ResponseCookies, ResponseHeaders, TypeEncodersMap
35
36
 
37
+ from litestar_vite.inertia.request import InertiaRequest
36
38
  from litestar_vite.inertia.routes import Routes
37
39
 
38
40
  from .plugin import InertiaPlugin
@@ -63,10 +65,11 @@ def get_shared_props(request: ASGIConnection[Any, Any, Any, Any]) -> Dict[str, A
63
65
  Be sure to call this before `self.create_template_context` if you would like to include the `flash` message details.
64
66
  """
65
67
  error_bag = request.headers.get("X-Inertia-Error-Bag", None)
66
- errors = request.session.pop("_errors", {})
67
- props = request.session.pop("_shared", {})
68
+ has_active_session = not (not request.session or request.scope["session"] is Empty)
69
+ errors: dict[str, Any] = request.session.pop("_errors", {}) if has_active_session else {}
70
+ props: dict[str, Any] = request.session.pop("_shared", {}) if has_active_session else {}
68
71
  flash: dict[str, list[str]] = defaultdict(list)
69
- for message in request.session.pop("_messages", []):
72
+ for message in cast("List[Dict[str,Any]]", request.session.pop("_messages", []) if has_active_session else []):
70
73
  flash[message["category"]].append(message["message"])
71
74
 
72
75
  inertia_plugin = cast("InertiaPlugin", request.app.plugins.get("InertiaPlugin"))
@@ -337,8 +340,12 @@ class InertiaBack(Redirect):
337
340
  """Initialize external redirect, Set status code to 409 (required by Inertia),
338
341
  and pass redirect url.
339
342
  """
343
+ referer = request.headers.get("referer", str(request.base_url))
344
+ inertia_enabled = getattr(request, "inertia_enabled", False) or getattr(request, "is_inertia", False)
345
+ if inertia_enabled:
346
+ referer = cast("InertiaRequest[Any, Any, Any]", request).inertia.referer or referer
340
347
  super().__init__(
341
- path=request.headers["Referer"],
348
+ path=request.headers.get("referer", str(request.base_url)),
342
349
  status_code=HTTP_307_TEMPORARY_REDIRECT if request.method == "GET" else HTTP_303_SEE_OTHER,
343
350
  cookies=request.cookies,
344
351
  **kwargs,
@@ -5,7 +5,7 @@
5
5
  groups = ["default", "dev", "docs", "linting", "nodeenv", "test"]
6
6
  strategy = ["inherit_metadata"]
7
7
  lock_version = "4.5.0"
8
- content_hash = "sha256:efdc42d268cebd9ea7f58466a138dc1315193223826403e74692ed057a2488f8"
8
+ content_hash = "sha256:55d55a5e5c3f3a4a552f16d6764c9dfd26ef3ddd3fbff51781236391c936d081"
9
9
 
10
10
  [[metadata.targets]]
11
11
  requires_python = ">=3.8"
@@ -482,14 +482,14 @@ files = [
482
482
 
483
483
  [[package]]
484
484
  name = "exceptiongroup"
485
- version = "1.2.1"
485
+ version = "1.2.2"
486
486
  requires_python = ">=3.7"
487
487
  summary = "Backport of PEP 654 (exception groups)"
488
488
  groups = ["default", "dev", "test"]
489
489
  marker = "python_version < \"3.11\""
490
490
  files = [
491
- {file = "exceptiongroup-1.2.1-py3-none-any.whl", hash = "sha256:5258b9ed329c5bbdd31a309f53cbfb0b155341807f6ff7606a1e801a891b29ad"},
492
- {file = "exceptiongroup-1.2.1.tar.gz", hash = "sha256:a4785e48b045528f5bfe627b6ad554ff32def154f42372786903b7abcfe1aa16"},
491
+ {file = "exceptiongroup-1.2.2-py3-none-any.whl", hash = "sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b"},
492
+ {file = "exceptiongroup-1.2.2.tar.gz", hash = "sha256:47c2edf7c6738fafb49fd34290706d1a1a2f4d1c6df275526b62cbb4aa5393cc"},
493
493
  ]
494
494
 
495
495
  [[package]]
@@ -662,13 +662,13 @@ files = [
662
662
 
663
663
  [[package]]
664
664
  name = "identify"
665
- version = "2.5.36"
665
+ version = "2.6.0"
666
666
  requires_python = ">=3.8"
667
667
  summary = "File identification library for Python"
668
668
  groups = ["linting"]
669
669
  files = [
670
- {file = "identify-2.5.36-py2.py3-none-any.whl", hash = "sha256:37d93f380f4de590500d9dba7db359d0d3da95ffe7f9de1753faa159e71e7dfa"},
671
- {file = "identify-2.5.36.tar.gz", hash = "sha256:e5e00f54165f9047fbebeb4a560f9acfb8af4c88232be60a488e9b68d122745d"},
670
+ {file = "identify-2.6.0-py2.py3-none-any.whl", hash = "sha256:e79ae4406387a9d300332b5fd366d8994f1525e8414984e1a59e058b2eda2dd0"},
671
+ {file = "identify-2.6.0.tar.gz", hash = "sha256:cb171c685bdc31bcc4c1734698736a7d5b6c8bf2e0c15117f4d469c8640ae5cf"},
672
672
  ]
673
673
 
674
674
  [[package]]
@@ -1239,7 +1239,7 @@ files = [
1239
1239
 
1240
1240
  [[package]]
1241
1241
  name = "polyfactory"
1242
- version = "2.16.0"
1242
+ version = "2.16.2"
1243
1243
  requires_python = "<4.0,>=3.8"
1244
1244
  summary = "Mock data generation factories"
1245
1245
  groups = ["default", "dev"]
@@ -1248,8 +1248,8 @@ dependencies = [
1248
1248
  "typing-extensions>=4.6.0",
1249
1249
  ]
1250
1250
  files = [
1251
- {file = "polyfactory-2.16.0-py3-none-any.whl", hash = "sha256:168d8e50b77e91e35e691e8b3eedac43d7e423a6857fa26d473def96d53f0ecf"},
1252
- {file = "polyfactory-2.16.0.tar.gz", hash = "sha256:03d8c706b70c4782ac8e637d0f6ab52760a7d11b712da5936a95a8f7022b2688"},
1251
+ {file = "polyfactory-2.16.2-py3-none-any.whl", hash = "sha256:e5eaf97358fee07d0d8de86a93e81dc56e3be1e1514d145fea6c5f486cda6ea1"},
1252
+ {file = "polyfactory-2.16.2.tar.gz", hash = "sha256:6d0d90deb85e5bb1733ea8744c2d44eea2b31656e11b4fa73832d2e2ab5422da"},
1253
1253
  ]
1254
1254
 
1255
1255
  [[package]]
@@ -1988,7 +1988,7 @@ files = [
1988
1988
 
1989
1989
  [[package]]
1990
1990
  name = "uvicorn"
1991
- version = "0.30.1"
1991
+ version = "0.30.3"
1992
1992
  requires_python = ">=3.8"
1993
1993
  summary = "The lightning-fast ASGI server."
1994
1994
  groups = ["dev"]
@@ -1998,13 +1998,13 @@ dependencies = [
1998
1998
  "typing-extensions>=4.0; python_version < \"3.11\"",
1999
1999
  ]
2000
2000
  files = [
2001
- {file = "uvicorn-0.30.1-py3-none-any.whl", hash = "sha256:cd17daa7f3b9d7a24de3617820e634d0933b69eed8e33a516071174427238c81"},
2002
- {file = "uvicorn-0.30.1.tar.gz", hash = "sha256:d46cd8e0fd80240baffbcd9ec1012a712938754afcf81bce56c024c1656aece8"},
2001
+ {file = "uvicorn-0.30.3-py3-none-any.whl", hash = "sha256:94a3608da0e530cea8f69683aa4126364ac18e3826b6630d1a65f4638aade503"},
2002
+ {file = "uvicorn-0.30.3.tar.gz", hash = "sha256:0d114d0831ff1adbf231d358cbf42f17333413042552a624ea6a9b4c33dcfd81"},
2003
2003
  ]
2004
2004
 
2005
2005
  [[package]]
2006
2006
  name = "uvicorn"
2007
- version = "0.30.1"
2007
+ version = "0.30.3"
2008
2008
  extras = ["standard"]
2009
2009
  requires_python = ">=3.8"
2010
2010
  summary = "The lightning-fast ASGI server."
@@ -2014,14 +2014,14 @@ dependencies = [
2014
2014
  "httptools>=0.5.0",
2015
2015
  "python-dotenv>=0.13",
2016
2016
  "pyyaml>=5.1",
2017
- "uvicorn==0.30.1",
2017
+ "uvicorn==0.30.3",
2018
2018
  "uvloop!=0.15.0,!=0.15.1,>=0.14.0; (sys_platform != \"cygwin\" and sys_platform != \"win32\") and platform_python_implementation != \"PyPy\"",
2019
2019
  "watchfiles>=0.13",
2020
2020
  "websockets>=10.4",
2021
2021
  ]
2022
2022
  files = [
2023
- {file = "uvicorn-0.30.1-py3-none-any.whl", hash = "sha256:cd17daa7f3b9d7a24de3617820e634d0933b69eed8e33a516071174427238c81"},
2024
- {file = "uvicorn-0.30.1.tar.gz", hash = "sha256:d46cd8e0fd80240baffbcd9ec1012a712938754afcf81bce56c024c1656aece8"},
2023
+ {file = "uvicorn-0.30.3-py3-none-any.whl", hash = "sha256:94a3608da0e530cea8f69683aa4126364ac18e3826b6630d1a65f4638aade503"},
2024
+ {file = "uvicorn-0.30.3.tar.gz", hash = "sha256:0d114d0831ff1adbf231d358cbf42f17333413042552a624ea6a9b4c33dcfd81"},
2025
2025
  ]
2026
2026
 
2027
2027
  [[package]]
@@ -19,14 +19,14 @@ classifiers = [
19
19
  "Topic :: Database",
20
20
  "Topic :: Database :: Database Engines/Servers",
21
21
  ]
22
- dependencies = ["litestar[jinja]>=2.4.0"]
22
+ dependencies = ["litestar[jinja]>=2.7.0"]
23
23
  description = "Vite plugin for Litestar"
24
24
  keywords = ["litestar", "vite"]
25
25
  license = { text = "MIT" }
26
26
  name = "litestar-vite"
27
27
  readme = "README.md"
28
28
  requires-python = ">=3.8"
29
- version = "0.2.0"
29
+ version = "0.2.2"
30
30
 
31
31
  [project.urls]
32
32
  Changelog = "https://cofin.github.io/litestar-vite/latest/changelog"
File without changes
File without changes
File without changes
File without changes