Skip to content

Conversation

@xuesichao
Copy link
Contributor

@xuesichao xuesichao commented Feb 21, 2025

Issue #:

Description of changes:

  • Migrate styled-components from v5 to v6 in SDK
  • Add support for styled-components v6 in peerDependencies

Testing

  1. Have you successfully run npm run build:release locally?
    Yes

  2. How did you test these changes?

  3. npm run build:release passes.

  4. I verified the following scenarios when installing styled-components v5 and v6 in the local React Component SDK:

  • Confirmed that the local Storybook appearance matches the production version, with no styled-components-related errors
  • Successfully tested the local meeting demo's end-to-end flow and UI after installing the React Component SDK tarball

When installing v6 in demo, both demo and SDK uses v6

❯ npm list styled-components
[email protected] /Users/sichax/Projects/amazon-chime-sdk/apps/meeting
├─┬ [email protected]
│ └── [email protected] deduped
└── [email protected]

When installing v5 in demo, both demo and SDK uses v5

❯ npm list styled-components     
[email protected] /Users/sichax/Projects/amazon-chime-sdk/apps/meeting
├─┬ [email protected]
│ └── [email protected] deduped
└─┬ [email protected]
  └─┬ [email protected]
    └── [email protected] deduped
  1. If you made changes to the component library, have you provided corresponding documentation changes?
    Yes

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@xuesichao xuesichao requested a review from a team as a code owner February 21, 2025 20:56
@xuesichao xuesichao force-pushed the styled-component-v6 branch 2 times, most recently from ebcb247 to 9fba533 Compare February 21, 2025 21:09
package.json Outdated
"fast-memoize": "^2.5.2",
"lodash.isequal": "^4.5.0",
"react-popper": "^2.3.0",
"stylis": "^4.3.6",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a peer dependency used by styled-components v6, a CSS preprocessor

import { BaseSdkProps } from '../Base';

const StyledPreview = styled(VideoTile)`
const StyledPreview = styled(VideoTile).withConfig(styledComponentsConfig)`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to handle a breaking change, in v5 the custom props such as isEnabledForScreenSharing is not forwarded to DOM element because it's not a native HTML attribute. So these non-native props are filtered. In v6 this filter is no longer provided by default, we follow the below guide to preserver the v5 behavior.

Comment on lines +36 to +38
& a:visited,
& a:hover,
& a:active {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +51 to +61
${isVertical(props.layout) ? layoutMap['left'] : layoutMap['bottom']};
box-shadow: ${props.theme.controlBar.shadow};
border: none;
height: ${(props: StyledControlBarProps) =>
isVertical(props.layout) && '100%'};
width: ${(props: StyledControlBarProps) =>
!isVertical(props.layout) && '100%'};
height: ${isVertical(props.layout) && '100%'};
width: ${!isVertical(props.layout) && '100%'};
}
${({ theme }) => theme.mediaQueries.max.xs} {
justify-content: ${(props: StyledControlBarProps) =>
isVertical(props.layout) ? 'center' : 'space-around'};
justify-content: ${isVertical(props.layout) ? 'center' : 'space-around'};
${unsetPosition}
${(props: StyledControlBarProps) =>
isVertical(props.layout) ? layoutMap['left'] : layoutMap['bottom']};
${isVertical(props.layout) ? layoutMap['left'] : layoutMap['bottom']};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to handle breaking TypeScript change, it becomes more strict.

<GlobalStyles />
<Canvas>
<Heading style={{ color: 'blue' }} level={3} tag="p">
<Heading style={{ color: 'blue' }} level={3} tag="span">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to handle a non-breaking error in storybook that a <p> can not be nested within another <p>

theme.colors[severity].primary};
color: ${({ theme, severity }) =>
theme.notification[severity].closeButton.text}};
theme.notification[severity].closeButton.text};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the extra }

width: 100%;
height: 100%;
object-fit: ${(props) => props.objectFit || 'cover'}};
object-fit: ${(props) => props.objectFit || 'cover'};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the extra }

@@ -1,4 +1,5 @@
import { WithTooltip } from '.'
import { Meta } from '@storybook/blocks';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"styled-components": "^5.3.9",
"styled-components": "^6.1.15",
"styled-system": "^5.1.5",
"stylis": "^4.3.6",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a CSS preprocessor, styled-components v6 requires this package

@xuesichao xuesichao force-pushed the styled-component-v6 branch 2 times, most recently from bc2a79a to cf6daad Compare February 24, 2025 18:39
ziyiz-amzn
ziyiz-amzn previously approved these changes Feb 24, 2025
// Forward custom props
if (additionalProps.includes(prop)) return true;

return isPropValid(prop);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For nested styled components, we add withConfig only to the bottom most one for the filtering. This way it won't block any react props being passing through a styled components.

For example:

const StyledVideoTile = styled.div.withConfig()`...`;

// React component 
const VideoTile = (props) => {
  return props.isActive? <StyledVideoTile/> : null
}

// Styled react component
const ContentTile = styled(VideoTile)`...`; // Do not use withConfig, because StyledVideoTile already have it, this way isActive will not be filtered.

<StyledContentTile isActive={true} />

* @returns Configuration object with shouldForwardProp function
*/
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const createStyledConfig = (additionalProps: string[] = []) => ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to export this func?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export is needed. The idea is that other components can use this function to forward custom props via additionalProps if needed. It's not being use at this moment.

@xuesichao xuesichao merged commit 9246a0d into main Feb 26, 2025
1 of 2 checks passed
@xuesichao xuesichao deleted the styled-component-v6 branch February 26, 2025 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants