Skip to content

Commit 1d2054c

Browse files
authoredOct 1, 2024
Protect @compiled/react/runtime/style-cache better in browser distributions. (#1715)
* Protect `@compiled/react/runtime/style-cache` better in browser distributions. Steps to replicate (inside of our internal repo). 1. Add Compiled to an `ssr.test.tsx` with the Atlassian SSR Jest library. 2. Run tests 3. 💥 This is because our bundler for browser dist transform `isServerEnvironment()` with `false` inline, so if something in/correctly pulls `dist/browser/…` all server tests are skipped. See: https://github.com/atlassian-labs/compiled/blob/9a15e7420c436ff959e67004b7c6f46bec08f606/packages/react/tsconfig.browser.json#L9 * Increase byte limit with new protection
1 parent c3c5660 commit 1d2054c

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed
 

‎.changeset/shy-bees-fly.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@compiled/react': patch
3+
---
4+
5+
Protect @compiled/react/dist/browser/runtime in environments without a document defined.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
},
153153
{
154154
"path": "./packages/react/dist/browser/runtime/style-cache.js",
155-
"limit": "99B",
155+
"limit": "118B",
156156
"import": "CC",
157157
"ignore": [
158158
"react"

‎packages/react/src/runtime/style-cache.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { ProviderComponent, UseCacheHook } from './types';
1111
*/
1212
const Cache: any = isServerEnvironment() ? createContext<Record<string, true> | null>(null) : {};
1313

14-
if (!isServerEnvironment()) {
14+
if (!isServerEnvironment() && typeof document !== 'undefined') {
1515
/**
1616
* Iterates through all found style elements generated when server side rendering.
1717
*

0 commit comments

Comments
 (0)