Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
69a334f
Clean CSS injection
compulim Oct 7, 2025
f88316d
Clean up nonce usage
compulim Oct 7, 2025
2b4cacb
Remove nonce from <ThemeProvider>
compulim Oct 7, 2025
d590d10
Rename <WebChatTheme> to <Inject*CSS>
compulim Oct 8, 2025
14ebc9a
Clean up
compulim Oct 8, 2025
a741a60
Add comment
compulim Oct 8, 2025
1a74333
Add comment
compulim Oct 8, 2025
b890931
Fix identifier
compulim Oct 8, 2025
bfd5f2d
Remove nonce requirement
compulim Oct 8, 2025
1c606e9
Direct inject after building style elements
compulim Oct 9, 2025
474af5a
Add entry
compulim Oct 9, 2025
67600b7
Remove launcher experience
compulim Oct 9, 2025
30aaac5
Fix imports
compulim Oct 9, 2025
948bf37
Fix imports
compulim Oct 9, 2025
1c9e842
Fix tests
compulim Oct 9, 2025
4bfc718
Better imports
compulim Oct 9, 2025
7b2f79f
Use Happy DOM
compulim Oct 9, 2025
0016d4c
Return children as-is
compulim Oct 9, 2025
6f13288
Merge branch 'main' into feat-clean-up-theme-provider
compulim Oct 9, 2025
9399590
Remove unnecessary files
compulim Oct 9, 2025
a986552
Dedupe across instances
compulim Oct 9, 2025
4bd60d9
Add test
compulim Oct 9, 2025
3559026
Use hooks
compulim Oct 9, 2025
fd4ae05
Mvoe from hook to leaf node
compulim Oct 9, 2025
382ba4b
Move to create CSS function
compulim Oct 10, 2025
3170c13
Fix tsup
compulim Oct 10, 2025
e23d3b3
Allow rectifying twice
compulim Oct 10, 2025
41066ad
Mark nonce as optional
compulim Oct 10, 2025
b60ae40
Reverse order
compulim Oct 10, 2025
e44e898
Add component
compulim Oct 10, 2025
74b2dde
Add /component
compulim Oct 10, 2025
7f65a52
Remove snapshots
compulim Oct 10, 2025
acba8f0
Fix script-0.mjs
compulim Oct 10, 2025
f45fc60
Fix script-0.mjs
compulim Oct 10, 2025
8b4e058
Fix styleOptions
compulim Oct 10, 2025
d361f11
Allow cascaded rectify style options
compulim Oct 11, 2025
c27f54e
Separate stylesRoot from fluent-theme
compulim Oct 11, 2025
8ccf86a
Mark stylesRoot as optional
compulim Oct 11, 2025
8264448
Componentize <InjectStyleElements>
compulim Oct 11, 2025
5ddcf8c
Fix --watch 200
compulim Oct 11, 2025
68ad21f
Fix flakiness
compulim Oct 11, 2025
ac14353
Fix test
compulim Oct 11, 2025
0f96477
Fix test
compulim Oct 11, 2025
15b68c3
Fix --watch 200
compulim Oct 11, 2025
7b10338
Move stylesheet to bottommost on re-inject
compulim Oct 11, 2025
597141b
Fix hideScrollToEndButton
compulim Oct 11, 2025
6a5fc7b
Fix hideScrollToEndButton
compulim Oct 11, 2025
c7b2465
Clean up
compulim Oct 12, 2025
b7e5c80
Clean up
compulim Oct 12, 2025
75ddff7
Clean up
compulim Oct 12, 2025
ae1c734
Rename *CSS -> *Stylesheet
compulim Oct 12, 2025
8693e87
Componentize as <FluentThemeStylesheet>
compulim Oct 12, 2025
2c0dbeb
Merge branch 'main' into feat-clean-up-theme-provider
compulim Oct 12, 2025
7b14061
Rename to <CSSCustomPropertiesContainer>
compulim Oct 12, 2025
d8899c7
Fix tests
compulim Oct 12, 2025
015793b
Fix styleRoots and import hooks
compulim Oct 12, 2025
58aec61
Add importmap for hook
compulim Oct 12, 2025
a461ee0
Merge branch 'main' into feat-clean-up-theme-provider
compulim Oct 13, 2025
e4c0709
Move InjectStyleElements to styles package
compulim Oct 14, 2025
77aba36
Yellow instead of white
compulim Oct 14, 2025
55274ef
Add styles as devDependencies
compulim Oct 14, 2025
fb6c67f
Fix import map
compulim Oct 14, 2025
fa184dc
Retrigger checks
compulim Oct 14, 2025
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: 0 additions & 5 deletions __tests__/html/hooks.useInjectStyles.changeNonce.js

This file was deleted.

5 changes: 0 additions & 5 deletions __tests__/html/hooks.useInjectStyles.changeRoot.js

This file was deleted.

5 changes: 0 additions & 5 deletions __tests__/html/hooks.useInjectStyles.dupeElement.js

This file was deleted.

5 changes: 0 additions & 5 deletions __tests__/html/hooks.useInjectStyles.js

This file was deleted.

5 changes: 0 additions & 5 deletions __tests__/html/hooks.useInjectStyles.link.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
const {
testHelpers: { createDirectLineEmulator },
WebChat: {
Components: { Composer },
internal: { useInjectStyles }
Components: { Composer, ThemeProvider }
}
} = window;

function createStyle(body) {
const styleElement = document.createElement('style');

styleElement.dataset['testid'] = 'style';
styleElement.innerHTML = body;

return styleElement;
Expand All @@ -39,32 +39,31 @@
return false;
};

const renderWithFunction = fn =>
const render = ({ elements, nonce, stylesRoot }) =>
new Promise(resolve =>
ReactDOM.render(
<Composer directLine={directLine} store={store}>
<RunFunction fn={() => resolve(fn && fn())} key={Date.now() + ''} />
</Composer>,
document.getElementById('webchat')
<ThemeProvider styles={elements} nonce={nonce} styleOptions={stylesRoot ? { stylesRoot } : {}} />,
document.getElementById('webchat'),
resolve
)
);

const styleElement = createStyle('main { background-color: Red!important; }');

await renderWithFunction(() => useInjectStyles([styleElement], '1'));
await host.snapshot();
await render({ elements: [styleElement], nonce: '1' });
await host.snapshot('local');

const allInjectedStyles1 = document.head.querySelectorAll('style:not([data-emotion]):not([data-webchat-injected])');
Comment thread
OEvgeny marked this conversation as resolved.
const allInjectedStyles1 = document.head.querySelectorAll('style[data-testid="style"]');

expect(allInjectedStyles1).toHaveLength(1);
expect(allInjectedStyles1[0]).toBe(styleElement);

await renderWithFunction(() => useInjectStyles([styleElement], '2'));
await render({ elements: [styleElement], nonce: '2' });

// No color should be applied as nonce don't match.
await host.snapshot();
await host.snapshot('local');

const allInjectedStyles2 = document.head.querySelectorAll('style:not([data-emotion]):not([data-webchat-injected])');
const allInjectedStyles2 = document.head.querySelectorAll('style[data-testid="style"]');

expect(allInjectedStyles2).toHaveLength(1);
expect(allInjectedStyles2[0]).toBe(styleElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
const {
testHelpers: { createDirectLineEmulator },
WebChat: {
Components: { Composer },
internal: { useInjectStyles }
Components: { Composer, ThemeProvider }
}
} = window;

function createStyle(body) {
const styleElement = document.createElement('style');

styleElement.dataset['testid'] = 'style';
styleElement.innerHTML = body;

return styleElement;
Expand All @@ -37,31 +37,28 @@
return false;
};

const renderWithFunction = (fn, props) =>
const render = ({ elements, nonce, stylesRoot }) =>
new Promise(resolve =>
ReactDOM.render(
<Composer directLine={directLine} store={store} {...props}>
<RunFunction fn={() => resolve(fn && fn())} key={Date.now() + ''} />
</Composer>,
document.getElementById('webchat')
<ThemeProvider styles={elements} nonce={nonce} styleOptions={stylesRoot ? { stylesRoot } : {}} />,
document.getElementById('webchat'),
resolve
)
);

const styleElement = createStyle('main { background-color: Red!important; }');

await renderWithFunction(() => useInjectStyles([styleElement]));
await host.snapshot();
await render({ elements: [styleElement] });
await host.snapshot('local');

expect([...document.head.querySelectorAll('style:not([data-emotion]):not([data-webchat-injected])')]).toEqual([styleElement]);
expect([...document.body.querySelectorAll('style:not([data-emotion]):not([data-webchat-injected])')]).toEqual([]);
expect([...document.head.querySelectorAll('style[data-testid="style"]')]).toEqual([styleElement]);
expect([...document.body.querySelectorAll('style[data-testid="style"]')]).toEqual([]);

await renderWithFunction(() => useInjectStyles([styleElement]), {
styleOptions: { stylesRoot: document.body }
});
await host.snapshot();
await render({ elements: [styleElement], stylesRoot: document.body });
await host.snapshot('local');

expect([...document.head.querySelectorAll('style:not([data-emotion]):not([data-webchat-injected])')]).toEqual([]);
expect([...document.body.querySelectorAll('style:not([data-emotion]):not([data-webchat-injected])')]).toEqual([styleElement]);
expect([...document.head.querySelectorAll('style[data-testid="style"]')]).toEqual([]);
expect([...document.body.querySelectorAll('style[data-testid="style"]')]).toEqual([styleElement]);
});
</script>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
const {
testHelpers: { createDirectLineEmulator },
WebChat: {
Components: { Composer },
internal: { useInjectStyles }
Components: { Composer, ThemeProvider }
}
} = window;

function createStyle(body) {
const styleElement = document.createElement('style');

styleElement.dataset['testid'] = 'style';
styleElement.innerHTML = body;

return styleElement;
Expand All @@ -37,33 +37,55 @@
return false;
};

const renderWithFunction = fn =>
const render = ({ elements, nonce, stylesRoot }) =>
new Promise(resolve =>
ReactDOM.render(
<Composer directLine={directLine} store={store}>
<RunFunction fn={() => resolve(fn && fn())} key={Date.now() + ''} />
</Composer>,
document.getElementById('webchat')
<ThemeProvider styles={elements} nonce={nonce} styleOptions={stylesRoot ? { stylesRoot } : {}} />,
document.getElementById('webchat'),
resolve
)
);

const styleElement = createStyle('main { background-color: Red!important; }');

await renderWithFunction(() => useInjectStyles([styleElement, styleElement]));
await host.snapshot();
await render({ elements: [styleElement, styleElement] });
await host.snapshot('local');

const allInjectedStyles1 = document.head.querySelectorAll('style:not([data-emotion]):not([data-webchat-injected])');
const allInjectedStyles1 = document.head.querySelectorAll(
'style[data-testid="style"]'
);

expect(allInjectedStyles1).toHaveLength(1);
expect(allInjectedStyles1[0]).toBe(styleElement);

await renderWithFunction(() => useInjectStyles([styleElement, styleElement]));
await host.snapshot();
await render({ elements: [styleElement, styleElement] });
await host.snapshot('local');

const allInjectedStyles2 = document.head.querySelectorAll('style:not([data-emotion]):not([data-webchat-injected])');
const allInjectedStyles2 = document.head.querySelectorAll(
'style[data-testid="style"]'
);

expect(allInjectedStyles2).toHaveLength(1);
expect(allInjectedStyles2[0]).toBe(styleElement);

await render({ elements: [styleElement] });
await host.snapshot('local');

const allInjectedStyles3 = document.head.querySelectorAll(
'style[data-testid="style"]'
);

expect(allInjectedStyles3).toHaveLength(1);
expect(allInjectedStyles3[0]).toBe(styleElement);

await render({ elements: [] });
await host.snapshot('local');

const allInjectedStyles4 = document.head.querySelectorAll(
'style[data-testid="style"]'
);

expect(allInjectedStyles4).toHaveLength(0);
});
</script>
</body>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script>
<script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.development.js"></script>
<script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.development.js"></script>
<script crossorigin="anonymous" src="/test-harness.js"></script>
<script crossorigin="anonymous" src="/test-page-object.js"></script>
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
</head>
<body>
<main id="webchat"></main>
<script type="text/babel" data-presets="env,stage-3,react">
const {
testHelpers: { createDirectLineEmulator },
WebChat: {
Components: { Composer, ThemeProvider }
}
} = window;

function createStyle(body) {
const styleElement = document.createElement('style');

styleElement.dataset['testid'] = 'style';
styleElement.innerHTML = body;

return styleElement;
}

run(async function () {
const { directLine, store } = createDirectLineEmulator();

const RunFunction = ({ fn }) => {
fn();

return false;
};

const render = ({ elements, nonce, stylesRoot }) =>
new Promise(resolve =>
ReactDOM.render(
<ThemeProvider styles={elements} nonce={nonce} styleOptions={stylesRoot ? { stylesRoot } : {}} />,
document.getElementById('webchat'),
resolve
)
);

const styleElement = createStyle('main { background-color: Red!important; }');

document.head.append(styleElement);

await render({ elements: [styleElement, styleElement] });
await host.snapshot('local');

const allInjectedStyles1 = document.head.querySelectorAll('style[data-testid="style"]');

expect(allInjectedStyles1).toHaveLength(2);
Comment thread
OEvgeny marked this conversation as resolved.
Outdated
expect(allInjectedStyles1[0]).toBe(styleElement);
expect(allInjectedStyles1[1]).not.toBe(styleElement);
expect(allInjectedStyles1[1]).toHaveProperty('textContent', styleElement.textContent);

await render({ elements: [styleElement, styleElement] });
await host.snapshot('local');

const allInjectedStyles2 = document.head.querySelectorAll('style[data-testid="style"]');

expect(allInjectedStyles2).toHaveLength(2);
expect(allInjectedStyles2[0]).toBe(styleElement);
expect(allInjectedStyles2[1]).not.toBe(styleElement);
expect(allInjectedStyles2[1]).toHaveProperty('textContent', styleElement.textContent);

await render({ elements: [styleElement] });
await host.snapshot('local');

const allInjectedStyles3 = document.head.querySelectorAll('style[data-testid="style"]');

expect(allInjectedStyles3).toHaveLength(2);
expect(allInjectedStyles3[0]).toBe(styleElement);
expect(allInjectedStyles3[1]).not.toBe(styleElement);
expect(allInjectedStyles3[1]).toHaveProperty('textContent', styleElement.textContent);

await render({ elements: [] });
await host.snapshot('local');

const allInjectedStyles4 = document.head.querySelectorAll('style[data-testid="style"]');

expect(allInjectedStyles4).toHaveLength(1);
expect(allInjectedStyles4[0]).toBe(styleElement);
});
</script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading