Skip to content

Commit

Permalink
Use relative URLs to resolve custom resources (#7705)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Feb 12, 2025
1 parent 8af58ab commit 56d9055
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
3 changes: 2 additions & 1 deletion panel/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ def _render_esm(cls, compiled: bool | Literal['compiling'] = True, server: bool
esm_path = cls._esm_path(compiled=compiled is True)
if esm_path:
if esm_path == cls._bundle_path and cls.__module__ in sys.modules and server:
esm = cls._component_resource_path(esm_path, compiled)
# Generate relative path to handle apps served on subpaths
esm = (state.rel_path or './') + cls._component_resource_path(esm_path, compiled)
if config.autoreload:
modified = hashlib.sha256(str(esm_path.stat().st_mtime).encode('utf-8')).hexdigest()
esm += f'?{modified}'
Expand Down
7 changes: 1 addition & 6 deletions panel/models/reactive_esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,12 +650,7 @@ export class ReactiveESM extends HTMLBox {
}
let url
if (this.bundle === "url") {
const parts = location.pathname.split("/")
let path = parts.slice(0, parts.length-1).join("/")
if (path.length) {
path += "/"
}
url = `${location.origin}/${path}${this.esm}`
url = this.esm
} else {
url = URL.createObjectURL(new Blob([this.compiled], {type: "text/javascript"}))
}
Expand Down

0 comments on commit 56d9055

Please sign in to comment.