-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/improve vite manifest handling (#21)
- Cache vite manifest content - Better type vite manifest - Allow for multiple css files to be in the manifest file - Remove use_typescript in favour of `entrypoint_filename` - Introduce root_directory to InertiaConfig instead of assuming it - Introduce assets_prefix to InertiaConfig instead of assuming it
- Loading branch information
Showing
13 changed files
with
358 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,40 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [0.1.6] - 2024-07-17 | ||
|
||
- Cache vite manifest content | ||
- Better type vite manifest | ||
- Allow for multiple css files to be in the manifest file | ||
- Deprecate use_typescript in favour of entrypoint_filename | ||
- Will be removed in 1.0.0 | ||
- Introduce root_directory to InertiaConfig instead of assuming it | ||
- Introduce assets_prefix to InertiaConfig instead of assuming it | ||
|
||
## [0.1.5] - 2024-07-17 | ||
|
||
- Introduce new dev dependency: BeautifulSoup | ||
- Use it instead of manual parsing as this is more reliable and less painful | ||
|
||
## [0.1.4] - 2024-05-31 | ||
|
||
* Handle better JSONification of Pydantic models | ||
* Use `json.loads(model.model_dump.json())` rather than `model.model_dump()` | ||
- Handle better JSONification of Pydantic models | ||
- Use `json.loads(model.model_dump.json())` rather than `model.model_dump()` | ||
To avoid issues with some common field types (UUID, datetime, etc.) | ||
* Expose a `_render_json` method on inertia to allow easier overriding. | ||
- Expose a `_render_json` method on inertia to allow easier overriding. | ||
|
||
## [0.1.3] - 2024-05-08 | ||
|
||
* Bump FastAPI version from 0.110.2 to 0.111.0 | ||
- Bump FastAPI version from 0.110.2 to 0.111.0 | ||
|
||
## [0.1.2] - 2024-04-23 | ||
|
||
* Update `README.md` and available versions | ||
- Update `README.md` and available versions | ||
|
||
## [0.1.1] - 2024-04-23 | ||
|
||
* Initial release. | ||
- Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
100 changes: 100 additions & 0 deletions
100
inertia/tests/test_backward_compatibility/test_deprecation_use_typescript.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import json | ||
import os | ||
from datetime import datetime | ||
|
||
from fastapi import FastAPI, Depends | ||
from typing import Annotated, cast | ||
|
||
from starlette.testclient import TestClient | ||
|
||
from inertia import Inertia, inertia_dependency_factory, InertiaResponse, InertiaConfig | ||
|
||
from inertia.tests.utils import assert_response_content | ||
|
||
app = FastAPI() | ||
manifest_json_ts = os.path.join( | ||
os.path.dirname(__file__), "..", "dummy_manifest_ts.json" | ||
) | ||
|
||
|
||
TypescriptInertiaDep = Annotated[ | ||
Inertia, | ||
Depends( | ||
inertia_dependency_factory( | ||
InertiaConfig( | ||
use_typescript=True, | ||
) | ||
) | ||
), | ||
] | ||
|
||
TypescriptProductionInertiaDep = Annotated[ | ||
Inertia, | ||
Depends( | ||
inertia_dependency_factory( | ||
InertiaConfig( | ||
manifest_json_path=manifest_json_ts, | ||
environment="production", | ||
use_typescript=True, | ||
) | ||
) | ||
), | ||
] | ||
|
||
PROPS = {"message": "hello from index", "created_at": datetime.now()} | ||
|
||
EXPECTED_PROPS = { | ||
**PROPS, | ||
"created_at": cast(datetime, PROPS["created_at"]).isoformat(), | ||
} | ||
|
||
COMPONENT = "IndexPage" | ||
|
||
|
||
@app.get("/typescript", response_model=None) | ||
async def typescript(inertia: TypescriptInertiaDep) -> InertiaResponse: | ||
return await inertia.render(COMPONENT, PROPS) | ||
|
||
|
||
@app.get("/typescript-production", response_model=None) | ||
async def typescript_production( | ||
inertia: TypescriptProductionInertiaDep, | ||
) -> InertiaResponse: | ||
return await inertia.render(COMPONENT, PROPS) | ||
|
||
|
||
def test_first_request_returns_html_typescript_still_works() -> None: | ||
with TestClient(app) as client: | ||
response = client.get("/typescript") | ||
assert response.status_code == 200 | ||
assert response.headers.get("content-type").split(";")[0] == "text/html" | ||
expected_url = str(client.base_url) + "/typescript" | ||
assert_response_content( | ||
response, | ||
expected_component=COMPONENT, | ||
expected_props=EXPECTED_PROPS, | ||
expected_url=expected_url, | ||
expected_script_asset_url="http://localhost:5173/src/main.ts", | ||
) | ||
|
||
|
||
def test_first_request_returns_html_production_typescript_still_works() -> None: | ||
with open(manifest_json_ts, "r") as manifest_file: | ||
manifest = json.load(manifest_file) | ||
|
||
css_files = [f"/{file}" for file in manifest["src/main.ts"]["css"]] | ||
js_file = manifest["src/main.ts"]["file"] | ||
js_file = f"/{js_file}" | ||
with TestClient(app) as client: | ||
response = client.get("/typescript-production") | ||
assert response.status_code == 200 | ||
assert response.headers.get("content-type").split(";")[0] == "text/html" | ||
expected_url = str(client.base_url) + "/typescript-production" | ||
assert_response_content( | ||
response, | ||
expected_component=COMPONENT, | ||
expected_props=EXPECTED_PROPS, | ||
expected_url=expected_url, | ||
expected_script_asset_url=js_file, | ||
expected_css_asset_urls=css_files, | ||
) |
Oops, something went wrong.