Bug description
Per document on STATIC_ASSETS_PREFIX in config, it should be the prefix of all static assets URLs. However, it's not true for most of JS and CSS files. I believe it's a bug in superset/extensions/__init__.py
. The UIManifestProcessor.get_manifest
method should add STATIC_ASSETS_PREFIX to all assets listed in manifest.
How to reproduce the bug
- Set STATIC_ASSETS_PREFIX to a custom host and restart Superset server.
- Reload Superset website and monitor network traffic in DevTools. We can see that most of JS and CSS files are not downloaded from the host we just set in step 1.
Screenshots/recordings
No response
Superset version
master / latest-dev
Python version
3.9
Node version
16
Browser
Chrome
Additional context
No response
Checklist
- [X] I have searched Superset docs and Slack and didn't find a solution to my problem.
- [X] I have searched the GitHub issue tracker and didn't find a similar bug report.
- [X] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
Comment From: dosubot[bot]
Hey @huandu, I'm here to help you with any bugs, questions, or contributions you might have for the repository. Let me know how I can assist you! 😊
The issue arises because the UIManifestProcessor.get_manifest
method does not prepend the STATIC_ASSETS_PREFIX
to the asset paths. The method currently returns paths like "/static/dist/main-js.js"
and "/static/dist/main-css.css"
without the prefix, even when STATIC_ASSETS_PREFIX
is set.
Here's the relevant part of the implementation:
def get_manifest(self) -> dict[str, Callable[[str], list[str]]]:
loaded_chunks = set()
def get_files(bundle: str, asset_type: str = "js") -> list[str]:
files = self.get_manifest_files(bundle, asset_type)
filtered_files = [f for f in files if f not in loaded_chunks]
for f in filtered_files:
loaded_chunks.add(f)
return filtered_files
return {
"js_manifest": lambda bundle: get_files(bundle, "js"),
"css_manifest": lambda bundle: get_files(bundle, "css"),
"assets_prefix": self.app.config["STATIC_ASSETS_PREFIX"]
if self.app
else "",
}
The assets_prefix
is correctly set in the returned dictionary, but it is not applied to the individual asset paths. This discrepancy leads to the URLs of scripts and CSS files missing the configured prefix [1][2].
To fix this, you would need to modify the get_files
function to prepend the STATIC_ASSETS_PREFIX
to each asset path.
To continue talking to Dosu, mention @dosu.
Comment From: rusackas
Thanks for opening the PR!
Comment From: rusackas
The PR has been closed, do you think we should close this issue as well? It hasn't been touched in ~5 months.
Comment From: rusackas
Closing as not-planned, but happy to reopen this if anyone is facing it and/or wants to oen a PR.