Better code structure
This commit is contained in:
parent
47ed43ba42
commit
6b5292d342
@ -8,23 +8,28 @@ import icons from './icons.json';
|
|||||||
|
|
||||||
class IconInner extends PureComponent {
|
class IconInner extends PureComponent {
|
||||||
createMarkup(markup) {
|
createMarkup(markup) {
|
||||||
|
|
||||||
// sanitize markup first:
|
// sanitize markup first:
|
||||||
let sanitizedMarkup = DOMPurify.sanitize(markup);
|
const sanitizedMarkup = this.sanitizeMarkup(markup);
|
||||||
|
|
||||||
// handling server rendering
|
|
||||||
if (!window) {
|
|
||||||
// We create a window out of JSDOM
|
|
||||||
const window = (new JSDOM('')).window;
|
|
||||||
// Plug it to DOMPurify
|
|
||||||
const DOMPurifyServer = DOMPurify(window);
|
|
||||||
// and then sanitize markup
|
|
||||||
sanitizedMarkup = DOMPurifyServer.sanitize(markup);
|
|
||||||
}
|
|
||||||
|
|
||||||
// now do the weird thing for dangerouslySetInnerHTML
|
// now do the weird thing for dangerouslySetInnerHTML
|
||||||
return { __html: sanitizedMarkup };
|
return { __html: sanitizedMarkup };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sanitizeMarkup(markup) {
|
||||||
|
// For server environement
|
||||||
|
if (!window) {
|
||||||
|
// We create a window out of JSDOM
|
||||||
|
const window = (new JSDOM('')).window;
|
||||||
|
// Then we plug it to DOMPurify
|
||||||
|
const DOMPurifyServer = DOMPurify(window);
|
||||||
|
// and finally sanitize the markup
|
||||||
|
return DOMPurifyServer.sanitize(markup);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sanitize the markup
|
||||||
|
return DOMPurify.sanitize(markup);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
// <g> is just a wrapper it does nothing except let me use valid JSX markup
|
// <g> is just a wrapper it does nothing except let me use valid JSX markup
|
||||||
// icons are based on generated icons.json from feather lib
|
// icons are based on generated icons.json from feather lib
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user