fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

[Bug]: custom renderer with nonce is not injecting nonce to all style tags generated by griffel core

Open AlexisGlez opened this issue 3 years ago • 4 comments

Library

React Components / v9 (@fluentui/react-components)

System Info

System:
    OS: macOS 13.5.2
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 234.89 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 116.0.5845.187
    Edge: 117.0.2045.35
    Firefox: 116.0.3
    Safari: 16.6

Are you reporting Accessibility issue?

no

Reproduction

I cannot provide a link as it is an internal MS repo

Bug Description

Actual Behavior

When using a custom renderer with a CSP nonce passed to the Fluent Provider, it seems that the @grifferl/core librart is not injecting the nonce to all style tags injected by it; causing some styles in our app to be broken.

export const WrapperFluentProvider: React.FunctionComponent<WrapperFluentProviderProps> = ({
	children,
	themeName,
	nonce,
}) => {
	const queryStringReader: QueryStringReader = new QueryStringReader()

	const theme = useTheme(themeName ?? (queryStringReader.getTheme() as ThemeType) ?? ThemeType.default)

	const additionalDOMRendererOptions = nonce ? { styleElementAttributes: { nonce } } : {}
	const renderer = useMemo(() => createDOMRenderer(document, additionalDOMRendererOptions), [])

	return (
		<RendererProvider renderer={renderer}>
			<Provider theme={theme} dir="ltr">
				{children}
			</Provider>
		</RendererProvider>
	)
}

image

image\

Note

This seems to be a regression bug in the latest iterations of the @griffel library. This bug does not happen with the following pinned versions in our side:

"@griffel/core": "1.11.0",
"@griffel/react": "1.5.7",

It happens if we upgrade those dependencies. So for now, we have just pinned them until this is fixed.

Expected Behavior

All style tags injected should have the nonce if specified.

Logs

No response

Requested priority

Normal

Products/sites affected

Microsoft Reading Progress in Teams

Are you willing to submit a PR to fix?

no

Validations

  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • [X] The provided reproduction is a minimal reproducible example of the bug.

AlexisGlez avatar Sep 21 '23 18:09 AlexisGlez

Hi @layershifter, I think this might be a regression in griffel. Would you be able to confirm?

sopranopillow avatar Sep 21 '23 20:09 sopranopillow

I believe that there is no bug, it's probably missing/improper configuration. It's visible on the screenshot:

image

(you have duplicated buckets for "t")

Check following:

  • yarn.lock to check how many entries it has for @griffel/core
    • if it's multiple => deduplicate, https://www.npmjs.com/package/yarn-deduplicate
  • put a debugger in createIsomorphicStyleSheet.ts and check what creates that style element with nonce (elements are created on demand, it should be visible what hook invoked creation)

https://github.com/microsoft/griffel/blob/480aba5a6d8a3b295c10dffe80c2ff4e228f9b3d/packages/core/src/renderer/createIsomorphicStyleSheet.ts#L12


Possible reason is that RendererProvider does not wrap all app and there is something that uses default renderer that does not have configured nonce.

layershifter avatar Sep 22 '23 07:09 layershifter

Our team was not installing any @griffel dependencies directly. They have been a dependency of FluentV9 all this time (and maybe from some other dependencies we are using? hard to tell). I looked into our lock file and there was only one @griffel dep installed.

Long time ago we had a similar issue in which FluentV9 was installed more than once, causing issues with the fluent provider. The way we fixed this issue was by forcing webpack to resolve all nested dependencies to use the same version of FluentV9 at the root of node modules with the resilve.alias object.

I have added @griffel dependencies to be resolved the same way in webpack and it seems that it is fixing the issue as well.

The issue can be closed as I was able to fix it from our side, but not sure if the outcome of this should be adding documentation about this.

Thanks for the help!

AlexisGlez avatar Sep 22 '23 21:09 AlexisGlez

closing based on convo - author unblocked

Hotell avatar Sep 27 '23 09:09 Hotell