Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ff3cb16
Change `Global` component to use the `StyleSheet` constructor of the …
Jack-Works Mar 10, 2022
7f8910a
Removed the direct dependency on from as it's no longer used that way
Andarist Mar 10, 2022
239f2d0
Version Packages (#2679)
github-actions[bot] Mar 10, 2022
2d3d7dd
Fixed `CacheProvider` demo in the docs (#2678)
pengx17 Mar 10, 2022
1a25293
Added `includeStyles` option to `createSerializer` to optionally disa…
thompsongl Apr 5, 2022
d935762
Fixed a false positive warning for `content` properties that included…
arturmuller Apr 5, 2022
8c1c7c7
Fixed a Prettier error
Andarist Apr 5, 2022
fc52bed
Update snapshots after renaming a test (#2711)
Andarist Apr 6, 2022
7a478fc
Version Packages (#2710)
github-actions[bot] Apr 6, 2022
3743483
Fixed an issue with `createEnzymeSerializer` not handling the recentl…
thompsongl Apr 7, 2022
6c9dbe5
Version Packages (#2716)
github-actions[bot] Apr 7, 2022
cd535bf
Update to new DocSearch index (#2718)
emmatown Apr 9, 2022
ae0f650
Fixed an issue in the minifying logic that could remove rules with th…
Andarist Apr 10, 2022
888377a
Version Packages (#2722)
github-actions[bot] Apr 10, 2022
409b237
Replace CodeSandbox link in bug report issue template (#2726)
srmagura Apr 16, 2022
6c652d9
Fix TS 4.7 error related to isPropValid
srmagura Apr 24, 2022
b575ef7
Merge branch 'main' of https://github.com/emotion-js/emotion into ts-…
srmagura Apr 24, 2022
69b3e06
Merge branch 'ts-april-23' into ts-merge
srmagura Apr 24, 2022
6bf9be3
Remove accidentally-committed .d.ts files
srmagura Apr 24, 2022
b9640a5
Fix unintentional breaking change to @emotion/memoize
srmagura Apr 24, 2022
f187b1d
Reorder function overloads in packages/memoize/src/index.ts
srmagura Apr 24, 2022
ba5f146
Make snapshots more readable (#2733)
SimenB Apr 25, 2022
7a3f608
Merge branch 'main' of https://github.com/emotion-js/emotion into ts-…
srmagura Apr 28, 2022
bf0a262
Merge pull request #2734 from emotion-js/preconstruct-upgrade
Andarist Apr 28, 2022
6c2d7a6
Allow any `Node` as container (#2728)
Peeja Apr 28, 2022
26e4e3e
Update "no component selectors" error message (#2727)
srmagura Apr 28, 2022
30f5cc4
Merge branch 'main' of https://github.com/emotion-js/emotion into ts-…
srmagura Apr 30, 2022
a485db3
styled: require prop to be a string
srmagura Apr 30, 2022
b45662d
Put in hacks to make .d.ts generation succeed for @emotion/eslint-plugin
srmagura Apr 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/big-years-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@emotion/serialize': patch
---

Changed the error message "Component selectors can only be used in conjunction with @emotion/babel-plugin" to reference the new SWC Emotion plugin which will support component selectors soon.
6 changes: 6 additions & 0 deletions .changeset/five-balloons-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@emotion/cache': patch
'@emotion/sheet': patch
---

TypeScript type for the `container` option has been adjusted. It will now accept a `ShadowRoot`, or any other kind of `Node`.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- This step can be removed from this document if we upgrade to the latest
version of Gatsby, which is compatible with sharp 0.28.0+ which does include
binaries for M1 Macs.
- (If using Windows) Enable Developer Mode in the Windows settings app. On Windows 11, this can be done by searching the start menu for "Developer settings" and then enabling the Developer Mode toggle switch.
- Run `yarn` in the repository's root directory to install everything you need for development.
- Run `yarn build` in the root directory to build the modules.

Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@
"react": "React",
"react/jsx-runtime": "ReactJSX",
"react/jsx-dev-runtime": "ReactJSXDev"
},
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
"newEntrypoints": true,
"newDistFilenames": true
}
},
"bugs": {
Expand Down Expand Up @@ -193,7 +189,7 @@
"@manypkg/cli": "^0.16.1",
"@mdx-js/mdx": "^1.6.22",
"@mdx-js/react": "^1.6.22",
"@preconstruct/cli": "1.1.34",
"@preconstruct/cli": "^2.1.5",
"@testing-library/react": "13.0.0-alpha.5",
"@types/jest": "^27.0.3",
"@types/node": "^10.11.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The prefix before class names. It will also be set as the value of the `data-emo

### `container`

`HTMLElement`
`Node`

A DOM node that emotion will insert all of its style tags into. This is useful for inserting styles into iframes or windows.

Expand Down
33 changes: 33 additions & 0 deletions packages/cache/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should accept container option 1`] = `
.emotion-0 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
color: blue;
}

<body>


<div
id="container"
>


<style
data-emotion="test-container"
data-s=""
>

.emotion-0{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;color:blue;}
</style>
</div>
<div>
<div
class="emotion-0"
/>
</div>
</body>
`;

exports[`should accept insertionPoint option 1`] = `
<head>

Expand Down
21 changes: 21 additions & 0 deletions packages/cache/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,24 @@ it('should accept insertionPoint option', () => {

expect(document.head).toMatchSnapshot()
})

it('should accept container option', () => {
const body = safeQuerySelector('body')

body.innerHTML = `
<div id="container" />
`

const cache = createCache({
key: 'test-container',
container: safeQuerySelector('#container')
})

render(
<CacheProvider value={cache}>
<div css={{ display: 'flex', color: 'blue' }} />
</CacheProvider>
)

expect(document.body).toMatchSnapshot()
})
2 changes: 1 addition & 1 deletion packages/cache/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ let createCache = (options /*: Options */) /*: EmotionCache */ => {
}
}
let inserted = {}
let container /*: HTMLElement */
let container /* : Node */
const nodesToHydrate = []
if (isBrowser) {
container = options.container || document.head
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface Options {
nonce?: string
stylisPlugins?: Array<StylisPlugin>
key: string
container?: HTMLElement
container?: Node
speedy?: boolean
/** @deprecate use `insertionPoint` instead */
prepend?: boolean
Expand Down
4 changes: 2 additions & 2 deletions packages/css/test/no-babel/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ exports[`css @supports 1`] = `
/>
`;

exports[`css component as selectors (object syntax) 1`] = `"Component selectors can only be used in conjunction with @emotion/babel-plugin."`;
exports[`css component as selectors (object syntax) 1`] = `"Component selectors can only be used in conjunction with @emotion/babel-plugin, the swc Emotion plugin, or another Emotion-aware compiler transform."`;

exports[`css component as selectors (object syntax) 2`] = `"The above error occurred in the <Styled(div)> component:"`;

exports[`css component selectors without target 1`] = `"Component selectors can only be used in conjunction with @emotion/babel-plugin."`;
exports[`css component selectors without target 1`] = `"Component selectors can only be used in conjunction with @emotion/babel-plugin, the swc Emotion plugin, or another Emotion-aware compiler transform."`;

exports[`css composition 1`] = `
.emotion-0 {
Expand Down
13 changes: 7 additions & 6 deletions packages/serialize/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ if (process.env.NODE_ENV !== 'production') {
}
}

const noComponentSelectorMessage =
'Component selectors can only be used in conjunction with ' +
'@emotion/babel-plugin, the swc Emotion plugin, or another Emotion-aware ' +
'compiler transform.'

function handleInterpolation(
mergedProps: unknown | undefined,
registered: RegisteredCache | undefined,
Expand All @@ -181,9 +186,7 @@ function handleInterpolation(
process.env.NODE_ENV !== 'production' &&
String(componentSelector) === 'NO_COMPONENT_SELECTOR'
) {
throw new Error(
'Component selectors can only be used in conjunction with @emotion/babel-plugin.'
)
throw new Error(noComponentSelectorMessage)
}
return componentSelector as unknown as string
}
Expand Down Expand Up @@ -324,9 +327,7 @@ function createStringFromObject(
key === 'NO_COMPONENT_SELECTOR' &&
process.env.NODE_ENV !== 'production'
) {
throw new Error(
'Component selectors can only be used in conjunction with @emotion/babel-plugin.'
)
throw new Error(noComponentSelectorMessage)
}
if (
Array.isArray(value) &&
Expand Down
2 changes: 1 addition & 1 deletion packages/sheet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sheet.insert('html { color: hotpink; }')
type Options = {
nonce?: string
key: string
container: HTMLElement
container: Node
speedy?: boolean
prepend?: boolean
}
Expand Down
21 changes: 21 additions & 0 deletions packages/sheet/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,24 @@ exports[`StyleSheet should work if insertionPoint is last element 1`] = `
<body />
</html>
`;

exports[`StyleSheet should work with a ShadowRoot container 1`] = `
<html>
<head />
<body>
<div />
</body>
</html>
`;

exports[`StyleSheet should work with a ShadowRoot container 2`] = `
HTMLCollection [
<style
data-emotion=""
data-s=""
>

html { color: hotpink; }
</style>,
]
`;
17 changes: 17 additions & 0 deletions packages/sheet/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ describe('StyleSheet', () => {
sheet.flush()
})

it('should work with a ShadowRoot container', () => {
const div = document.createElement('div')
// $FlowFixMe
document.body.appendChild(div)
const container = div.attachShadow({ mode: 'open' })
const sheet = new StyleSheet({ ...defaultOptions, container })
expect(sheet.container).toBe(container)
sheet.insert(rule)
expect(document.documentElement).toMatchSnapshot()
// The shadowRoot is not serialized in the snapshot, so we need to take a
// separate snapshot of the shadowRoot's children.
expect(container.children).toMatchSnapshot()
expect(sheet.tags).toHaveLength(1)
expect(sheet.tags[0].parentNode).toBe(container)
sheet.flush()
})

it('should accept prepend option', () => {
const head = safeQuerySelector('head')
const otherStyle = document.createElement('style')
Expand Down
5 changes: 3 additions & 2 deletions packages/sheet/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function sheetForTag(tag: HTMLStyleElement): CSSStyleSheet {
export type Options = {
nonce?: string
key: string
container: HTMLElement
container: Node
speedy?: boolean
prepend?: boolean
insertionPoint?: HTMLElement
Expand All @@ -63,7 +63,8 @@ export class StyleSheet {
isSpeedy: boolean
ctr: number
tags: HTMLStyleElement[]
container: HTMLElement
// Using Node instead of HTMLElement since container may be a ShadowRoot
container: Node
key: string
nonce: string | undefined
prepend: boolean | undefined
Expand Down
6 changes: 6 additions & 0 deletions packages/sheet/types/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ styleSheet.flush()
styleSheet.flush(undefined as any)
// $ExpectError
styleSheet.flush(...(undefined as any as Array<any>))

const shadowRoot = document.createElement('div').attachShadow({ mode: 'open' })
const shadowStyleSheet = new StyleSheet({
key: 'abc',
container: shadowRoot
})
Loading