superset: CSS styling doesn't work in Handlebars chart
Bug description
CSS code defined in “CSS styles” section of Handlebars chart settings isn’t applied to HTML template. It is shown as plain text on the chart instead.
How to reproduce the bug
- Disable ESCAPE_MARKDOWN_HTML, enable HTML_SANITIZATION, allow CSS with HTML_SANITIZATION_SCHEMA_EXTENSIONS in
superset_config.pyas follows:
FEATURE_FLAGS = {
"ESCAPE_MARKDOWN_HTML": False,
"HTML_SANITIZATION": True,
}
HTML_SANITIZATION_SCHEMA_EXTENSIONS = {
"attributes": {
"*": ["style","className"],
},
"tagNames": ["style"],
}
- Create a Handlebars chart with one column (“descr” in this example) added from any dataset.
- Set up HTML template as follows:
<ul class="data-list">
{{#each data}}
<li>{{descr}}</li>
{{/each}}
</ul>
- Set up CSS for the chart:
.data-list {
background-color: yellow;
}
- Observe your CSS code in the preview as a plain text.
Screenshots/recordings
Superset version
master / latest-dev
Python version
3.11
Node version
18 or greater
Browser
Chrome
Additional context
While investigating this issue, I dived into Handlebars code. There is a section in superset-frontend/plugins/plugin-chart-handlebars/src/components/Handlebars/HandlebarsViewer.tsx at lines 35-43 that seemingly retrieves HTML sanitization and schema overrides. I went to the browser console and printed these variables with this snippet:
const appContainer = document.getElementById('app');
const { common } = JSON.parse(
appContainer?.getAttribute('data-bootstrap') || '{}',
);
const htmlSanitization = common?.conf?.HTML_SANITIZATION;
const htmlSchemaOverrides =
common?.conf?.HTML_SANITIZATION_SCHEMA_EXTENSIONS;
console.log(htmlSanitization);
console.log(htmlSchemaOverrides);
The output returns true and empty object respectively despite the overrides are configured (see “How to reproduce the bug” section). It appears that either I’m doing something wrong, or the overrides are not read from the superset_config.py.
Checklist
- I have searched Superset docs and Slack and didn’t find a solution to my problem.
- I have searched the GitHub issue tracker and didn’t find a similar bug report.
- 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.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 28 (18 by maintainers)
Thanks for your help, @sfirke !
I couldn’t find a flag similar to
DEBUG_MODEin the documentation. But as CSS styling actually works at 4.0.2 production and this issue is mostly caused by my own local setup, I think it will be easier to just disableHTML_SANITIZATIONfor now.Seems like at this moment I’ve hit the wall with the bot. I would really appreciate if the community could help me to proceed with this issue.
Certainly! Here is an example of a full
superset_config.pywith HTML sanitization configured:This configuration includes the
HTML_SANITIZATIONandHTML_SANITIZATION_SCHEMA_EXTENSIONSsettings to allow CSS styles and class names in the HTML content [1].To continue talking to Dosu, mention @dosu.