Skip to content

Commit

Permalink
Protect @compiled/react/runtime/style-cache better in browser distr…
Browse files Browse the repository at this point in the history
…ibutions. (#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
  • Loading branch information
kylorhall-atlassian authored Oct 1, 2024
1 parent c3c5660 commit 1d2054c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-bees-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@compiled/react': patch
---

Protect @compiled/react/dist/browser/runtime in environments without a document defined.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
},
{
"path": "./packages/react/dist/browser/runtime/style-cache.js",
"limit": "99B",
"limit": "118B",
"import": "CC",
"ignore": [
"react"
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/runtime/style-cache.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { ProviderComponent, UseCacheHook } from './types';
*/
const Cache: any = isServerEnvironment() ? createContext<Record<string, true> | null>(null) : {};

if (!isServerEnvironment()) {
if (!isServerEnvironment() && typeof document !== 'undefined') {
/**
* Iterates through all found style elements generated when server side rendering.
*
Expand Down

0 comments on commit 1d2054c

Please sign in to comment.