diff --git a/docs/source/about/changelog.rst b/docs/source/about/changelog.rst index b683ab4a4..9535d0b67 100644 --- a/docs/source/about/changelog.rst +++ b/docs/source/about/changelog.rst @@ -23,7 +23,9 @@ more info, see the :ref:`Contributor Guide `. Unreleased ---------- -Nothing yet... +**Fixed** + +- :pull:`1118` - `module_from_template` is broken with a recent release of `requests` v1.0.2 diff --git a/src/py/reactpy/reactpy/web/utils.py b/src/py/reactpy/reactpy/web/utils.py index cf8b8638b..295559496 100644 --- a/src/py/reactpy/reactpy/web/utils.py +++ b/src/py/reactpy/reactpy/web/utils.py @@ -1,7 +1,7 @@ import logging import re from pathlib import Path, PurePosixPath -from urllib.parse import urlparse +from urllib.parse import urlparse, urlunparse import requests @@ -130,7 +130,11 @@ def resolve_module_exports_from_source( def _resolve_relative_url(base_url: str, rel_url: str) -> str: if not rel_url.startswith("."): - return rel_url + if rel_url.startswith("/"): + # copy scheme and hostname from base_url + return urlunparse(urlparse(base_url)[:2] + urlparse(rel_url)[2:]) + else: + return rel_url base_url = base_url.rsplit("/", 1)[0] diff --git a/temp.py b/temp.py new file mode 100644 index 000000000..5104013b6 --- /dev/null +++ b/temp.py @@ -0,0 +1,29 @@ +from fastapi import FastAPI + +from reactpy import html, web +from reactpy.backend.fastapi import configure + +mui = web.module_from_template( + "react", + "@mui/x-date-pickers", + fallback="please wait loading...", +) + + +# Create calendar with material ui +DatePicker = web.export(mui, "DatePicker") + + +def Mycalender(): + return html.div( + DatePicker( + { + "label": "Basic date picker", + }, + "my calender", + ), + ) + + +app = FastAPI() +configure(app, Mycalender)