Skip to content
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

Regression: JSComponent fails with AttributeError in Panel 1.6.1+ when using External Files for _esm and _stylesheets #7779

Closed
leighshepperson-gresearch opened this issue Mar 13, 2025 · 1 comment · Fixed by #7809

Comments

@leighshepperson-gresearch
Copy link

leighshepperson-gresearch commented Mar 13, 2025

ALL software version info

(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc should be added within the dropdown below.)

Panel: 1.6.1
Bokeh: 3.2.0
Python: 3.10.4
Notebook: 6.5.4
OS: Ubuntu 22.04
Browser: Chrome 110

Description of expected behavior and the observed behavior

The JSComponent should be served without errors when using _esm and _stylesheets External Files, whether they are defined as Path objects or as strings, as it does in Panel 1.5.5.

Observed Behavior:
An AttributeError is raised in Panel >= 1.6.1 (including pre-release) when attempting to use lstrip on a PosixPath object in https://github.com/holoviz/panel/blob/main/panel/io/resources.py#L679, even when using string paths.

Complete, minimal, self-contained example code that reproduces the issue

The example from the documentation has this issue https://panel.holoviz.org/reference/custom_components/JSComponent.html#external-files

from pathlib import Path
import param
import panel as pn
from panel.custom import JSComponent

pn.extension()

class CounterButton(JSComponent):
    value = param.Integer()

    # Using Path objects
    _esm = Path("counter_button.js")
    _stylesheets = [Path("counter_button.css")]

pn.serve(CounterButtonString())

# Alternatively, using string paths
class CounterButtonString(JSComponent):
    value = param.Integer()

    # Using string paths
    _esm = "counter_button.js"
    _stylesheets = ["counter_button.css"]

pn.serve(CounterButtonString())

Stack traceback and/or browser JavaScript console output

Traceback (most recent call last):
  File "/home/admin/PycharmProjects/PythonProject/.venv/lib/python3.10/site-packages/tornado/web.py", line 1790, in _execute
    result = await result
  File "/home/admin/PycharmProjects/PythonProject/.venv/lib/python3.10/site-packages/panel/io/server.py", line 524, in get
    page = server_html_page_for_session(
  File "/home/admin/PycharmProjects/PythonProject/.venv/lib/python3.10/site-packages/panel/io/server.py", line 295, in server_html_page_for_session
    bundle = bundle_resources(doc.roots, resources)
  File "/home/admin/PycharmProjects/PythonProject/.venv/lib/python3.10/site-packages/panel/io/resources.py", line 429, in bundle_resources
    css_files.extend(css_resources.css_files)
  File "/home/admin/PycharmProjects/PythonProject/.venv/lib/python3.10/site-packages/panel/io/resources.py", line 751, in css_files
    self.extra_resources(files, '_bundle_css')
  File "/home/admin/PycharmProjects/PythonProject/.venv/lib/python3.10/site-packages/panel/io/resources.py", line 679, in extra_resources
    if not isurl(resource) and not resource.lstrip('./').startswith('static/extensions'):
AttributeError: 'PosixPath' object has no attribute 'lstrip'
500 GET / (::1) 92.50ms
@philippjfr
Copy link
Member

Good catch, thanks! Will fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants