Skip to content

Commit

Permalink
Ensure _bundle_css is added as resource and resolved on baseclass (#7691
Browse files Browse the repository at this point in the history
)

* Ensure _bundle_css is added as resource and resolved on baseclass

* Ignore type

* Small fixes
  • Loading branch information
philippjfr authored Feb 7, 2025
1 parent 8463ff8 commit fe88d56
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 7 additions & 4 deletions panel/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,14 @@ def _bundle_path(cls) -> os.PathLike | None:

@classproperty
def _bundle_css(cls):
esm_path = cls._esm_path(compiled=True)
try:
esm_path = cls._esm_path(compiled=True)
except ValueError:
return []
css_path = esm_path.with_suffix('.css')
if css_path.is_file():
return css_path
return None
return [css_path]
return []

@classmethod
def _esm_path(cls, compiled: bool = True) -> os.PathLike | None:
Expand Down Expand Up @@ -698,7 +701,7 @@ class CounterButton(pn.custom.ReactComponent):
_react_version = '18.3.1'

@classproperty # type: ignore
def _exports__(cls) -> ExportSpec:
def _exports__(cls) -> ExportSpec: # type: ignore
imports = cls._importmap.get('imports', {})
exports: dict[str, list[str | tuple[str, ...]]] = {
"react": ["*React"],
Expand Down
8 changes: 7 additions & 1 deletion panel/io/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,13 @@ def extra_resources(self, resources, resource_type):
"""
from ..reactive import ReactiveCustomBase
for model in param.concrete_descendents(ReactiveCustomBase).values():
if not (getattr(model, resource_type, None) and model._loaded()):
cls_files = getattr(model, resource_type, None)
if not (cls_files and model._loaded()):
continue
for cls in model.__mro__[1:]:
supcls_files = getattr(cls, resource_type, [])
if supcls_files == cls_files:
model = cls
for resource in getattr(model, resource_type, []):
if state.rel_path:
resource = resource.lstrip(state.rel_path+'/')
Expand Down Expand Up @@ -740,6 +745,7 @@ def css_files(self):

files = super().css_files
self.extra_resources(files, '__css__')
self.extra_resources(files, '_bundle_css')
css_files = self.adjust_paths([
css for css in files if self.mode != 'inline' or not is_cdn_url(css)
])
Expand Down

0 comments on commit fe88d56

Please sign in to comment.