Fix CDN requests in server mode for loading.css and es-module-shims - #8408
Conversation
|
Related issue #6161 |
|
Thanks @nojaf, this looks good. |
|
@philippjfr thanks, sorry for all the formatting changes. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8408 +/- ##
==========================================
- Coverage 86.09% 85.45% -0.64%
==========================================
Files 349 349
Lines 54821 54841 +20
==========================================
- Hits 47199 46867 -332
- Misses 7622 7974 +352 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
We don't have a formatter. I know VS Code have an option to I think the easiest way is doing something like |
- Use get_dist_path() instead of CDN_DIST for loading.css in reactive.py - Handle multiple npm CDN prefixes in bundled_files() - Add patch_stylesheet case for LOCAL_DIST to custom dist_url - Update test assertions to accept both CDN and local loading.css paths
|
Thanks for the feedback on minimizing the diff @hoxbro ! I've force-pushed a cleaner version. One thing that would help future contributions: would you consider adding a formatter (like |
|
Appreciate it! I do think we should adopt more formatting rules, i.e. consistent quoting would be nice. Will do that one of these days. |
|
Sounds great! I do notice that some tests fail @philippjfr, I'm a bit confused if they are related or not? Any thoughts? |
|
Very confused too, just ran them locally without issue. I'll restart them but it's a bit worrying that some of the resource related tests are failing, seemingly randomly. |
|
Guess it's not totally random, ubuntu fails consistently. |
|
Well not that consistently apparently, one just passed and when I run it on my linux box and it works just fine. |
|
Okay, I think this was a result of bokeh document state leaking across tests. Should be resolved now. |
|
Thanks for merging this, @philippjfr! Much appreciated. This problem has been on our radar for quite some time, and I'm excited to see it fixed! |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Fixes external CDN requests when running Panel in server mode, ensuring all resources are served locally.
Problem
When deploying Panel applications in server mode with
PANEL_NPM_CDNconfigured to an internal registry, the app still made external network requests to:https://cdn.holoviz.org/panel/<version>/dist/css/loading.csshttps://cdn.jsdelivr.net/npm/es-module-shims@^1.10.0/dist/es-module-shims.min.jsThis is problematic for air-gapped environments or deployments with strict network policies that require all resources to be served locally.
Root Causes
1.
loading.css(panel/reactive.py)The loading stylesheet URL was hardcoded using
CDN_DIST, which always points tocdn.holoviz.orgregardless of the resource mode:2.
es-module-shims(panel/io/resources.py)This one is more subtle. The
ReactiveESMclass defines__javascript_raw__at class definition time (import time), capturing the default CDN URL beforePANEL_NPM_CDNis read:Later,
bundled_files()checks if URLs start withconfig.npm_cdnto map them to local files. But sinceconfig.npm_cdnnow reflects the custom registry URL while the captured URL still hascdn.jsdelivr.net, the check fails and the file isn't served locally.Solution
1.
loading.cssUse
get_dist_path()instead ofCDN_DIST. This function respects the current resource mode and returns the local path in server mode.2.
es-module-shimsExpand the prefix matching in
bundled_files()to recognize all common NPM CDN prefixes:This ensures URLs captured at import time with the default CDN are still correctly mapped to local bundled files, regardless of the runtime
PANEL_NPM_CDNsetting.