Skip to content

Commit 9595494

Browse files
Address remaining code review feedback
1. Restore SSR parity: Component now returns inline <style> element during SSR instead of null, maintaining behavior with original createGlobalStyle which rendered during SSR. This prevents flash of unstyled content. 2. Fix misleading test name: Renamed test from "only creates one style element" to "creates a separate style element for each component instance" to accurately reflect the actual behavior. 3. Update test comment: Changed "still only one style element" to "each instance creates its own style element" to match assertions. 4. Update SSR test: Changed test name from "renders nothing" to "renders style element for SSR" to reflect new behavior. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent b2bfcbe commit 9595494

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/components/ManageCookies.node.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ManageCookiesLink } from "./ManageCookies";
55

66
// For prerendering
77
describe('ManageCookies outside a browser', () => {
8-
it('renders nothing', () => {
8+
it('renders style element for SSR', () => {
99
const tree = renderer.create(
1010
<ManageCookiesLink />
1111
).toJSON();

src/components/ManageCookies.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ describe('ManageCookies', () => {
373373
expect(unmountedStyles.length).toBe(0);
374374
});
375375

376-
it('only creates one style element when component is rendered multiple times', () => {
376+
it('creates a separate style element for each component instance', () => {
377377
// Mount first instance
378378
const { unmount: unmount1 } = render(<ManageCookiesLink />);
379379

@@ -385,7 +385,7 @@ describe('ManageCookies', () => {
385385
// Mount second instance (without unmounting first)
386386
const { unmount: unmount2 } = render(<ManageCookiesLink />);
387387

388-
// Verify still only one style element (each instance has its own ref)
388+
// Verify each instance creates its own style element
389389
styles = Array.from(document.head.querySelectorAll('style'))
390390
.filter(style => style.textContent?.includes('.cky-btn-revisit'));
391391
expect(styles.length).toBe(2); // Each component instance adds its own style

src/components/ManageCookies.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ export const ManageCookiesLink = ({children, className, wrapper, ...props}: Mana
130130
}, 100); // Small delay to allow CookieYes to add the modal to DOM
131131
}, [inBrowser, onClick, clearInitTimeout, cleanupObserverAndTimeouts]);
132132

133-
if (!inBrowser) { return null; }
133+
// For SSR, render the style element inline to prevent flash of unstyled content
134+
if (!inBrowser) {
135+
return <style dangerouslySetInnerHTML={{ __html: '.cky-btn-revisit { display: none; }' }} />;
136+
}
134137

135138
const button = <ButtonLink
136139
ref={buttonRef}

0 commit comments

Comments
 (0)