Skip to content

need to copy scheme from base url #1118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/source/about/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ more info, see the :ref:`Contributor Guide <Creating a Changelog Entry>`.
Unreleased
----------

Nothing yet...
**Fixed**

- :pull:`1118` - `module_from_template` is broken with a recent release of `requests`


v1.0.2
Expand Down
8 changes: 6 additions & 2 deletions src/py/reactpy/reactpy/web/utils.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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]

Expand Down
29 changes: 29 additions & 0 deletions temp.py
Original file line number Diff line number Diff line change
@@ -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)