Skip to content

Commit ca080b5

Browse files
RoyEJohnsonCopilot
andcommitted
Copilot suggestions
Card.css import order issue Co-Authored-By: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 98eb7c2 commit ca080b5

4 files changed

Lines changed: 46 additions & 19 deletions

File tree

src/app/components/DynamicContentStyles.tsx

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,40 @@ const DynamicContentStyles = React.forwardRef<HTMLElement, DynamicContentStylesP
7272
const [dataDynamicStyle, styles] = getStyles(disable, queryStyles, book, bookStylesUrl, archiveLoader);
7373

7474
// Inject dynamic styles into a <style> tag
75-
React.useEffect(() => {
76-
if (!styles || typeof document === 'undefined') {
77-
return;
75+
React.useEffect(() => {
76+
if (!styles || typeof document === 'undefined') {
77+
return;
78+
}
79+
80+
const globalKey = '__rexDynamicContentStyles__';
81+
const globalStore = globalThis as any;
82+
const store = (globalStore[globalKey] ||= {
83+
count: 0,
84+
element: null as HTMLStyleElement | null,
85+
});
86+
87+
store.count += 1;
88+
89+
if (!store.element || !document.head.contains(store.element)) {
90+
store.element = document.createElement('style');
91+
store.element.setAttribute('data-dynamic-content-styles', 'true');
92+
document.head.appendChild(store.element);
93+
}
94+
95+
store.element.textContent = `
96+
[data-dynamic-style="true"] {
97+
${styles}
7898
}
99+
`;
79100

80-
// Create a <style> element with scoped styles
81-
const styleElement = document.createElement('style');
82-
styleElement.setAttribute('data-dynamic-content-styles', 'true');
83-
styleElement.textContent = `
84-
[data-dynamic-style="true"] {
85-
${styles}
86-
}
87-
`;
88-
document.head.appendChild(styleElement);
89-
90-
// Cleanup function to remove the style element when component unmounts or styles change
91-
return () => {
92-
document?.head.removeChild(styleElement); // no document returns early
93-
};
94-
}, [styles]);
101+
return () => {
102+
store.count -= 1;
103+
if (store.count <= 0 && store.element) {
104+
store.element.remove();
105+
store.element = null;
106+
}
107+
};
108+
}, [styles]);
95109

96110
return <div data-dynamic-style={dataDynamicStyle} {...otherProps} ref={ref}>
97111
{children}

src/app/notifications/components/Card.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
padding: 1rem;
2626
}
2727

28+
.notification-p a,
29+
.notification-header a {
30+
color: #027eb5;
31+
cursor: pointer;
32+
text-decoration: underline;
33+
}
34+
35+
.notification-p a:hover,
36+
.notification-header a:hover {
37+
color: #0064a0;
38+
}
39+
2840
@media (max-width: 75em) {
2941
.notification-p {
3042
padding: 0;

src/app/notifications/components/Card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import classNames from 'classnames';
33
import theme from '../../theme';
4-
import './Card.css';
4+
/* CSS imported in src/app/notifications/index.ts */
55

66
interface GroupProps extends React.HTMLAttributes<HTMLDivElement> {
77
theme?: unknown;

src/app/notifications/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as actions from './actions';
22
import * as hooks from './hooks';
33
import reducer from './reducer';
4+
import './components/Card.css';
45

56
export {
67
actions,

0 commit comments

Comments
 (0)