Skip to content

Commit

Permalink
Pass context.styleContainer to DomHandler.createInlineStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
mondaychen committed Jan 5, 2024
1 parent 6f25e3b commit 18ef7fe
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion components/lib/carousel/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export const Carousel = React.memo(

const createStyle = () => {
if (!carouselStyle.current) {
carouselStyle.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce);
carouselStyle.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce, context && context.styleContainer);
}

let innerHTML = `
Expand Down
2 changes: 1 addition & 1 deletion components/lib/cascadeselect/CascadeSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export const CascadeSelect = React.memo(

const createStyle = () => {
if (!styleElementRef.current) {
styleElementRef.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce);
styleElementRef.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce, context && context.styleContainer);

const selector = `${attributeSelectorState}_panel`;
const innerHTML = `
Expand Down
2 changes: 1 addition & 1 deletion components/lib/contextmenu/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const ContextMenu = React.memo(

const createStyle = () => {
if (!styleElementRef.current) {
styleElementRef.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce);
styleElementRef.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce, context && context.styleContainer);

const selector = `${attributeSelectorState}`;
const innerHTML = `
Expand Down
4 changes: 2 additions & 2 deletions components/lib/datatable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,12 +791,12 @@ export const DataTable = React.forwardRef((inProps, ref) => {
};

const createStyleElement = () => {
styleElement.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce);
styleElement.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce, context && context.styleContainer);
};

const createResponsiveStyle = () => {
if (!responsiveStyleElement.current) {
responsiveStyleElement.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce);
responsiveStyleElement.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce, context && context.styleContainer);

let tableSelector = `.p-datatable-wrapper ${isVirtualScrollerDisabled() ? '' : '> .p-virtualscroller'} > .p-datatable-table`;
let selector = `.p-datatable[${attributeSelector.current}] > ${tableSelector}`;
Expand Down
2 changes: 1 addition & 1 deletion components/lib/dialog/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export const Dialog = React.forwardRef((inProps, ref) => {
};

const createStyle = () => {
styleElement.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce);
styleElement.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce, context && context.styleContainer);

let innerHTML = '';

Expand Down
2 changes: 1 addition & 1 deletion components/lib/galleria/GalleriaThumbnails.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export const GalleriaThumbnails = React.memo(

const createStyle = () => {
if (!thumbnailsStyle.current) {
thumbnailsStyle.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce);
thumbnailsStyle.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce, context && context.styleContainer);
}

let innerHTML = `
Expand Down
2 changes: 1 addition & 1 deletion components/lib/megamenu/MegaMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ export const MegaMenu = React.memo(

const createStyle = () => {
if (!styleElementRef.current) {
styleElementRef.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce);
styleElementRef.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce, context && context.styleContainer);

const selector = `${attributeSelectorState}`;
const innerHTML = `
Expand Down
2 changes: 1 addition & 1 deletion components/lib/orderlist/OrderList.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export const OrderList = React.memo(

const createStyle = () => {
if (!styleElementRef.current) {
styleElementRef.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce);
styleElementRef.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce, context && context.styleContainer);

let innerHTML = `
@media screen and (max-width: ${props.breakpoint}) {
Expand Down
2 changes: 1 addition & 1 deletion components/lib/overlaypanel/OverlayPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const OverlayPanel = React.forwardRef((inProps, ref) => {

const createStyle = () => {
if (!styleElement.current) {
styleElement.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce);
styleElement.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce, context && context.styleContainer);

let innerHTML = '';

Expand Down
2 changes: 1 addition & 1 deletion components/lib/picklist/PickList.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export const PickList = React.memo(

const createStyle = () => {
if (!styleElementRef.current) {
styleElementRef.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce);
styleElementRef.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce, context && context.styleContainer);

let innerHTML = `
@media screen and (max-width: ${props.breakpoint}) {
Expand Down
2 changes: 1 addition & 1 deletion components/lib/tieredmenu/TieredMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ export const TieredMenu = React.memo(

const createStyle = () => {
if (!styleElementRef.current) {
styleElementRef.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce);
styleElementRef.current = DomHandler.createInlineStyle((context && context.nonce) || PrimeReact.nonce, context && context.styleContainer);

const selector = `${attributeSelectorState}`;
const innerHTML = `
Expand Down
6 changes: 3 additions & 3 deletions components/lib/utils/DomHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1067,19 +1067,19 @@ export default class DomHandler {
return false;
}

static createInlineStyle(nonce) {
static createInlineStyle(nonce, styleContainer = document.head) {
let styleElement = document.createElement('style');

DomHandler.addNonce(styleElement, nonce);
document.head.appendChild(styleElement);
styleContainer.appendChild(styleElement);

return styleElement;
}

static removeInlineStyle(styleElement) {
if (this.isExist(styleElement)) {
try {
document.head.removeChild(styleElement);
styleElement.parentNode.removeChild(styleElement);
} catch (error) {
// style element may have already been removed in a fast refresh
}
Expand Down
2 changes: 1 addition & 1 deletion components/lib/utils/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export declare class DomHandler {
static applyStyle(el: HTMLElement, style: any): void;
static exportCSV(csv: any, filename: string): void;
static saveAs(file: { name: string; url: any }): boolean;
static createInlineStyle(nonce?: string): HTMLStyleElement;
static createInlineStyle(nonce?: string, styleContainer?: ShadowRoot | HTMLElement): HTMLStyleElement;
static removeInlineStyle(styleElement: HTMLStyleElement): HTMLStyleElement | null;
static getTargetElement(target: any): HTMLElement | null;
}
Expand Down

0 comments on commit 18ef7fe

Please sign in to comment.