Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated JSX namespace with direct import #5547

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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/slow-fishes-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'styled-components': patch
---

fix jsx support for react 19
4 changes: 2 additions & 2 deletions packages/styled-components/src/constructors/styled.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import React, { JSX } from 'react';
import createStyledComponent from '../models/StyledComponent';
import { BaseObject, KnownTarget, WebTarget } from '../types';
import domElements, { SupportedHTMLElements } from '../utils/domElements';
Expand All @@ -14,7 +14,7 @@ const baseStyled = <Target extends WebTarget, InjectedProps extends object = Bas
>(createStyledComponent, tag);

const styled = baseStyled as typeof baseStyled & {
[E in SupportedHTMLElements]: StyledInstance<'web', E, React.JSX.IntrinsicElements[E]>;
[E in SupportedHTMLElements]: StyledInstance<'web', E, JSX.IntrinsicElements[E]>;
};

// Shorthands for all valid HTML Elements
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment node
*/
import React from 'react';
import React, { JSX } from 'react';
import ReactDOMServer from 'react-dom/server';
import ServerStyleSheet from '../../models/ServerStyleSheet';
import { stripComments, stripWhitespace } from '../../test/utils';
Expand All @@ -12,7 +12,7 @@ describe(`createGlobalStyle`, () => {

function setup() {
return {
renderToString(comp: React.JSX.Element) {
renderToString(comp: JSX.Element) {
return ReactDOMServer.renderToString(comp);
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { JSX } from 'react';
import ReactDOM from 'react-dom';
import { act, Simulate } from 'react-dom/test-utils';
import ReactTestRenderer from 'react-test-renderer';
Expand All @@ -19,7 +19,7 @@ describe(`createGlobalStyle`, () => {

return {
container,
render(comp: React.JSX.Element) {
render(comp: JSX.Element) {
ReactDOM.render(comp, container);
},
cleanup() {
Expand Down
4 changes: 2 additions & 2 deletions packages/styled-components/src/hoc/withTheme.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import React, { JSX } from 'react';
import { ThemeContext } from '../models/ThemeProvider';
import { AnyComponent, ExecutionProps } from '../types';
import determineTheme from '../utils/determineTheme';
import getComponentName from '../utils/getComponentName';
import hoist from '../utils/hoist';

export default function withTheme<T extends AnyComponent>(Component: T) {
const WithTheme = React.forwardRef<T, React.JSX.LibraryManagedAttributes<T, ExecutionProps>>(
const WithTheme = React.forwardRef<T, JSX.LibraryManagedAttributes<T, ExecutionProps>>(
(props, ref) => {
const theme = React.useContext(ThemeContext);
const themeProp = determineTheme(props, theme, Component.defaultProps);
Expand Down
4 changes: 2 additions & 2 deletions packages/styled-components/src/models/ServerStyleSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { JSX } from 'react';
import type * as streamInternal from 'stream';
import { Readable } from 'stream';
import { IS_BROWSER, SC_ATTR, SC_ATTR_VERSION, SC_VERSION } from '../constants';
Expand Down Expand Up @@ -35,7 +35,7 @@ export default class ServerStyleSheet {
return `<style ${htmlAttr}>${css}</style>`;
};

collectStyles(children: any): React.JSX.Element {
collectStyles(children: any): JSX.Element {
if (this.sealed) {
throw styledError(2);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/styled-components/src/models/ThemeProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useMemo } from 'react';
import React, { JSX, useContext, useMemo } from 'react';
import styledError from '../utils/error';
import isFunction from '../utils/isFunction';

Expand Down Expand Up @@ -86,7 +86,7 @@ export function useTheme(): DefaultTheme {
/**
* Provide a theme to an entire react component tree via context
*/
export default function ThemeProvider(props: Props): React.JSX.Element | null {
export default function ThemeProvider(props: Props): JSX.Element | null {
const outerTheme = React.useContext(ThemeContext);
const themeContext = useMemo(
() => mergeTheme(props.theme, outerTheme),
Expand Down
8 changes: 4 additions & 4 deletions packages/styled-components/src/test/props.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Fragment } from 'react';
import React, { Fragment, JSX } from 'react';
import TestRenderer from 'react-test-renderer';
import { getRenderedCSS, resetStyled } from './utils';

Expand Down Expand Up @@ -127,7 +127,7 @@ describe('props', () => {
});

it('allows custom prop filtering for components', () => {
const InnerComp = (props: React.JSX.IntrinsicElements['div']) => <div {...props} />;
const InnerComp = (props: JSX.IntrinsicElements['div']) => <div {...props} />;
const Comp = styled(InnerComp).withConfig({
shouldForwardProp: prop => !['filterThis'].includes(prop),
})<{ filterThis: string; passThru: string }>`
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('props', () => {
});

it('should filter out props when using "as" to a custom component', () => {
const AsComp = (props: React.JSX.IntrinsicElements['div']) => <div {...props} />;
const AsComp = (props: JSX.IntrinsicElements['div']) => <div {...props} />;
const Comp = styled('div').withConfig({
shouldForwardProp: prop => !['filterThis'].includes(prop),
})<{ filterThis: string; passThru: string }>`
Expand All @@ -202,7 +202,7 @@ describe('props', () => {
});

it('can set computed styles based on props that are being filtered out', () => {
const AsComp = (props: React.JSX.IntrinsicElements['div']) => <div {...props} />;
const AsComp = (props: JSX.IntrinsicElements['div']) => <div {...props} />;
const Comp = styled('div').withConfig({
shouldForwardProp: prop => !['filterThis'].includes(prop),
})<{ filterThis: string; passThru: string }>`
Expand Down
4 changes: 2 additions & 2 deletions packages/styled-components/src/test/ssr.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { resetStyled } from './utils';

import React from 'react';
import React, { JSX } from 'react';
import { renderToNodeStream, renderToString } from 'react-dom/server';
import stylisRTLPlugin from 'stylis-plugin-rtl';
import createGlobalStyle from '../constructors/createGlobalStyle';
Expand Down Expand Up @@ -306,7 +306,7 @@ describe('ssr', () => {
});

it('should handle errors while streaming', () => {
function ExplodingComponent(): React.JSX.Element {
function ExplodingComponent(): JSX.Element {
throw new Error('ahhh');
}

Expand Down
4 changes: 2 additions & 2 deletions packages/styled-components/src/test/types.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* This file is meant for typing-related tests that don't need to go through Jest.
*/
import React from 'react';
import React, { JSX } from 'react';
import { css, CSSProp, IStyledComponent, StyledObject } from '../index';
import styled from '../index-standalone';
import { DataAttributes } from '../types';
Expand Down Expand Up @@ -309,7 +309,7 @@ const StyledDiv = styled.div``;

const CustomComponent = (({ ...props }) => {
return <StyledDiv {...props} />;
}) as IStyledComponent<'web', React.JSX.IntrinsicElements['div']>;
}) as IStyledComponent<'web', JSX.IntrinsicElements['div']>;

const StyledCustomComponent = styled(CustomComponent)``;

Expand Down
4 changes: 2 additions & 2 deletions packages/styled-components/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as CSS from 'csstype';
import React from 'react';
import React, { JSX } from 'react';
import ComponentStyle from './models/ComponentStyle';
import { DefaultTheme } from './models/ThemeProvider';
import createWarnTooManyClasses from './utils/createWarnTooManyClasses';
Expand Down Expand Up @@ -217,7 +217,7 @@ export interface PolymorphicComponent<R extends Runtime, BaseProps extends objec
ForwardedAsTarget extends StyledTarget<R> | void = void,
>(
props: PolymorphicComponentProps<R, BaseProps, AsTarget, ForwardedAsTarget>
): React.JSX.Element;
): JSX.Element;
}

export interface IStyledComponentBase<R extends Runtime, Props extends object = BaseObject>
Expand Down
Loading