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

UI: Upgrade manager to react 18 #24514

Merged
merged 66 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
064b5fa
chore: upgrade to react 18
agriffis Mar 18, 2023
6fad767
fix: call react 18 createRoot instead of ReactDOM.render
agriffis Mar 18, 2023
7ed139d
chore: update react-test-renderer
agriffis Mar 18, 2023
11d6265
fix: kill enzyme test, not compatible with react 18
agriffis Mar 18, 2023
ba182ea
fix: update typing since react 18
agriffis Mar 19, 2023
219feba
fix: ignore ReactDOM.render warning for PreviewWeb.integration.test.ts
agriffis Mar 19, 2023
5c64218
chore: update to @testing-library/user-event 14
agriffis Mar 19, 2023
97939d4
fix: link tests async with user-event 14
agriffis Mar 19, 2023
f66e38a
fix: update ui exports
agriffis Mar 19, 2023
1565bab
Merge remote-tracking branch 'origin/next' into chore/react-18
valentinpalkovic Apr 17, 2023
6f0a8f7
Merge branch 'next' into chore/react-18
ndelangen Apr 17, 2023
80e8e9c
complete the upgrade
ndelangen Apr 17, 2023
6270e13
solve type change upstream
ndelangen Apr 17, 2023
51c85fa
add type
ndelangen Apr 17, 2023
5426c8e
fix type problem after upgrade
ndelangen Apr 17, 2023
5696726
type fixes
ndelangen Apr 17, 2023
69aa4b7
fix type issues
ndelangen Apr 17, 2023
3f5441f
fixes for types
ndelangen Apr 17, 2023
d7b2fc1
fixes for types
ndelangen Apr 17, 2023
cc198b3
fixes for types
ndelangen Apr 17, 2023
8980375
type fixes
ndelangen Apr 17, 2023
a5f2977
fix types
ndelangen Apr 17, 2023
cdf8917
types fixes
ndelangen Apr 17, 2023
9009c58
Update svelte check
kasperpeulen Apr 17, 2023
e5676e6
Fix react type test
kasperpeulen Apr 17, 2023
7e99f08
this package depends on React16 and can't be pre-bundled
ndelangen Apr 18, 2023
ca90ec0
fix types after react18 upgrade
ndelangen Apr 18, 2023
69b364e
fixing types
ndelangen Apr 18, 2023
2800f97
fixes for types
ndelangen Apr 18, 2023
0656f89
Remove React 18 type overrides and add additional types to fix lib
valentinpalkovic Apr 18, 2023
8a83f82
Fix theme type export to ensure proper functionality of Storybook themes
valentinpalkovic Apr 18, 2023
26992ad
Merge branch 'next' into chore/react-18
ndelangen Apr 19, 2023
6bcb18a
fix sandbox script after some upgrades broke it 🤬
ndelangen Apr 19, 2023
f0bab30
Merge branch 'next' into chore/react-18
ndelangen Apr 19, 2023
695190d
sync version of react-dom
ndelangen Apr 19, 2023
17cd638
Fix interaction tests on chromatic
valentinpalkovic Apr 20, 2023
f5f51f8
Merge branch 'next' into chore/react-18
ndelangen Apr 26, 2023
3df4a31
Merge branch 'next' into chore/react-18
ndelangen Apr 26, 2023
379116b
Merge branch 'next' into chore/react-18
valentinpalkovic Apr 27, 2023
1400d5d
Merge branch 'next' into chore/react-18
ndelangen May 3, 2023
e303b06
upgrades
ndelangen May 3, 2023
87fe9b4
fix typing issue
ndelangen May 3, 2023
9fd3d50
fixes
ndelangen May 3, 2023
c4d8272
Merge branch 'next' into chore/react-18
ndelangen May 3, 2023
3337c88
Merge branch 'next' into chore/react-18
ndelangen May 19, 2023
8e3a4d6
Merge branch 'next' into pr/agriffis/21673
ndelangen May 23, 2023
2161673
Merge branch 'release-8-0' into pr/agriffis/21673-2
ndelangen Oct 11, 2023
9a24441
Merge branch 'norbert/remove-storyshots' into pr/agriffis/21673-2
ndelangen Oct 11, 2023
b9107ee
fixes
ndelangen Oct 11, 2023
f725832
add exceptions for ts
ndelangen Oct 12, 2023
3ab81a2
change tests
ndelangen Oct 12, 2023
210002e
fix linting
ndelangen Oct 12, 2023
ca3e9b0
Merge branch 'norbert/remove-storyshots' into pr/agriffis/21673-2
ndelangen Oct 12, 2023
ab28071
Merge branch 'norbert/remove-storyshots' into pr/agriffis/21673-2
ndelangen Oct 18, 2023
ad1e0b9
skip test, over commenting it out
ndelangen Oct 18, 2023
8e3b336
Merge branch 'release-8-0' into pr/ndelangen/24511
ndelangen Oct 18, 2023
c1f20bf
Merge branch 'release-8-0' into norbert/react18
ndelangen Oct 19, 2023
14d094a
fix check
ndelangen Oct 19, 2023
ff50f69
ensure the preview is done loading after navigation
ndelangen Oct 19, 2023
78bcb62
fix state & e2e tests
ndelangen Oct 19, 2023
b2c6a49
simplify
ndelangen Oct 19, 2023
829fba6
fix tests
ndelangen Oct 19, 2023
856d535
delete redundant typings file
ndelangen Oct 19, 2023
ae3ee2e
Merge branch 'release-8-0' into norbert/react18
ndelangen Oct 19, 2023
74cc852
fix bench script
ndelangen Oct 19, 2023
4792ba1
Merge branch 'norbert/react18' of github.com:storybookjs/storybook in…
ndelangen Oct 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions code/.yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ unsafeHttpWhitelist:

yarnPath: ../.yarn/releases/yarn-3.5.1.cjs
installStatePath: '../.yarn/code-install-state.gz'
# Sometimes you get a "The remote archive doesn't match the expected checksum" error, uncommenting this line will fix it
# checksumBehavior: 'update'
2 changes: 1 addition & 1 deletion code/addons/a11y/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"react-resize-detector": "^7.1.2"
},
"devDependencies": {
"@testing-library/react": "^11.2.2",
"@testing-library/react": "^14.0.0",
"resize-observer-polyfill": "^1.5.1",
"typescript": "~5.2.2"
},
Expand Down
5 changes: 4 additions & 1 deletion code/addons/a11y/src/components/A11yContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ const defaultResult = {
violations: [],
};

export const A11yContextProvider: React.FC<A11yContextProviderProps> = ({ active, ...props }) => {
export const A11yContextProvider: React.FC<React.PropsWithChildren<A11yContextProviderProps>> = ({
active,
...props
}) => {
const [results, setResults] = useAddonState<Results>(ADDON_ID, defaultResult);
const [tab, setTab] = React.useState(0);
const [highlighted, setHighlighted] = React.useState<string[]>([]);
Expand Down
4 changes: 2 additions & 2 deletions code/addons/a11y/src/components/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ const List = styled.div(({ theme }) => ({

interface TabsProps {
tabs: {
label: JSX.Element;
panel: JSX.Element;
label: React.ReactElement;
panel: React.ReactElement;
items: Result[];
type: RuleType;
}[];
Expand Down
7 changes: 5 additions & 2 deletions code/addons/actions/src/components/ActionLogger/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FC } from 'react';
import type { FC, PropsWithChildren } from 'react';
import React, { Fragment } from 'react';
import { styled, withTheme } from '@storybook/theming';
import type { Theme } from '@storybook/theming';
Expand All @@ -9,7 +9,10 @@ import { ActionBar, ScrollArea } from '@storybook/components';
import { Action, InspectorContainer, Counter } from './style';
import type { ActionDisplay } from '../../models';

const UnstyledWrapped: FC<{ className?: string }> = ({ children, className }) => (
const UnstyledWrapped: FC<PropsWithChildren<{ className?: string }>> = ({
children,
className,
}) => (
<ScrollArea horizontal vertical className={className}>
{children}
</ScrollArea>
Expand Down
4 changes: 2 additions & 2 deletions code/addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@
},
"devDependencies": {
"@rollup/pluginutils": "^5.0.2",
"react": "^16.14.0",
"react-dom": "^16.8.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "~5.2.2",
"vite": "^4.0.4"
},
Expand Down
9 changes: 6 additions & 3 deletions code/addons/docs/src/DocsRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { PropsWithChildren } from 'react';
import React, { Component } from 'react';
import { renderElement, unmountElement } from '@storybook/react-dom-shim';
import type { Renderer, Parameters, DocsContextProps, DocsRenderFunction } from '@storybook/types';
Expand All @@ -10,9 +11,11 @@ export const defaultComponents: Record<string, any> = {
...HeadersMdx,
};

class ErrorBoundary extends Component<{
showException: (err: Error) => void;
}> {
class ErrorBoundary extends Component<
PropsWithChildren<{
showException: (err: Error) => void;
}>
> {
state = { hasError: false };

static getDerivedStateFromError() {
Expand Down
33 changes: 17 additions & 16 deletions code/addons/interactions/src/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,32 +148,33 @@ export const Panel = memo<{ storyId: string }>(function PanelMemoized({ storyId
},
[STORY_RENDER_PHASE_CHANGED]: (event) => {
if (event.newPhase === 'preparing') {
set((s) => ({
set({
controlStates: INITIAL_CONTROL_STATES,
isErrored: false,
pausedAt: undefined,
interactions: [],
isPlaying: false,
isRerunAnimating: false,
scrollTarget,
collapsed: new Set() as Set<Call['id']>,
hasException: false,
caughtException: undefined,
interactionsCount: 0,
}));
});
return;
}
set((s) => ({
...s,
isPlaying: event.newPhase === 'playing',
pausedAt: undefined,
...(event.newPhase === 'rendering'
? {
isErrored: false,
caughtException: undefined,
}
: {}),
}));
set((s) => {
const newState: typeof s = {
...s,
isPlaying: event.newPhase === 'playing',
pausedAt: undefined,
...(event.newPhase === 'rendering'
? {
isErrored: false,
caughtException: undefined,
}
: {}),
};

return newState;
});
},
[STORY_THREW_EXCEPTION]: () => {
set((s) => ({ ...s, isErrored: true }));
Expand Down
2 changes: 1 addition & 1 deletion code/addons/interactions/src/components/MethodCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export const MethodCall = ({
callId ? (
<MethodCall key={`elem${index}`} call={callsById.get(callId)} callsById={callsById} />
) : (
<span key={`elem${index}`}>{elem}</span>
<span key={`elem${index}`}>{elem as any}</span>
),
<wbr key={`wbr${index}`} />,
<span key={`dot${index}`}>.</span>,
Expand Down
4 changes: 2 additions & 2 deletions code/addons/jest/src/components/Message.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FC } from 'react';
import type { FC, ReactElement } from 'react';
import React, { Fragment } from 'react';
import { styled } from '@storybook/theming';

Expand All @@ -12,7 +12,7 @@ const passStartToken = '[32m';
const stackTraceStartToken = 'at';
const titleEndToken = ':';

type MsgElement = string | JSX.Element;
type MsgElement = string | ReactElement;

class TestDetail {
description!: MsgElement[];
Expand Down
17 changes: 11 additions & 6 deletions code/addons/links/src/react/components/link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ describe('LinkTo', () => {
});

describe('events', () => {
it('should select the kind and story on click', () => {
const channel = {
emit: jest.fn(),
on: jest.fn(),
} as any;
it('should select the kind and story on click', async () => {
const channel = mockChannel() as any;
mockAddons.getChannel.mockReturnValue(channel);

render(
Expand All @@ -74,7 +71,15 @@ describe('LinkTo', () => {
link
</LinkTo>
);
userEvent.click(screen.getByText('link'));

await waitFor(() => {
expect(screen.getByText('link')).toHaveAttribute(
'href',
'originpathname?path=/story/foo--bar'
);
});

await userEvent.click(screen.getByText('link'));

expect(channel.emit).toHaveBeenLastCalledWith(
SELECT_STORY,
Expand Down
2 changes: 1 addition & 1 deletion code/addons/storysource/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"tiny-invariant": "^1.3.1"
},
"devDependencies": {
"@types/react": "^16.14.34",
"@types/react": "^18.0.37",
"@types/react-syntax-highlighter": "11.0.5",
"typescript": "~5.2.2"
},
Expand Down
7 changes: 2 additions & 5 deletions code/e2e-tests/addon-actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import { SbPage } from './util';
const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001';

test.describe('addon-actions', () => {
test.beforeEach(async ({ page }) => {
await page.goto(storybookUrl);
await new SbPage(page).waitUntilLoaded();
});

test('should trigger an action', async ({ page }) => {
await page.goto(storybookUrl);
const sbPage = new SbPage(page);
sbPage.waitUntilLoaded();

await sbPage.navigateToStory('example/button', 'primary');
const root = sbPage.previewRoot();
Expand Down
2 changes: 2 additions & 0 deletions code/e2e-tests/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export class SbPage {

const selected = await storyLink.getAttribute('data-selected');
await expect(selected).toBe('true');

await this.previewRoot();
}

async waitUntilLoaded() {
Expand Down
4 changes: 2 additions & 2 deletions code/frameworks/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"@storybook/telemetry": "workspace:*",
"@storybook/types": "workspace:*",
"@types/node": "^18.0.0",
"@types/react": "^16.14.34",
"@types/react-dom": "^16.9.14",
"@types/react": "^18.0.37",
"@types/react-dom": "^18.0.11",
"@types/semver": "^7.3.4",
"@types/webpack-env": "^1.18.0",
"find-up": "^5.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { PropsWithChildren } from 'react';
import React, { useMemo } from 'react';
import { HeadManagerContext } from 'next/dist/shared/lib/head-manager-context.shared-runtime';
import initHeadManager from 'next/dist/client/head-manager';
Expand All @@ -12,7 +13,7 @@ type HeadManagerValue = {
nonce?: string | undefined;
};

const HeadManagerProvider: React.FC = ({ children }) => {
const HeadManagerProvider: React.FC<PropsWithChildren> = ({ children }) => {
const headManager: HeadManagerValue = useMemo(initHeadManager, []);
headManager.getIsSsr = () => false;

Expand Down
6 changes: 5 additions & 1 deletion code/frameworks/nextjs/src/routing/app-router-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ const getParallelRoutes = (segmentsList: Array<string>): FlightRouterState => {
return [] as any;
};

const AppRouterProvider: React.FC<AppRouterProviderProps> = ({ children, action, routeParams }) => {
const AppRouterProvider: React.FC<React.PropsWithChildren<AppRouterProviderProps>> = ({
children,
action,
routeParams,
}) => {
const { pathname, query, segments = [], ...restRouteParams } = routeParams;

const tree: FlightRouterState = [pathname, { children: getParallelRoutes([...segments]) }];
Expand Down
3 changes: 2 additions & 1 deletion code/frameworks/nextjs/src/routing/page-router-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Globals } from '@storybook/csf';
import { RouterContext } from 'next/dist/shared/lib/router-context.shared-runtime';
import type { PropsWithChildren } from 'react';
import React from 'react';
import type { RouteParams } from './types';

Expand All @@ -9,7 +10,7 @@ type PageRouterProviderProps = {
globals: Globals;
};

const PageRouterProvider: React.FC<PageRouterProviderProps> = ({
const PageRouterProvider: React.FC<PropsWithChildren<PageRouterProviderProps>> = ({
children,
action,
routeParams,
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/nextjs/src/styledJsx/decorator.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

let StyleRegistry: React.FC;
let StyleRegistry: React.FC<React.PropsWithChildren>;

try {
// next >= v12
Expand Down
44 changes: 0 additions & 44 deletions code/frameworks/react-vite/src/typings.d.ts

This file was deleted.

44 changes: 0 additions & 44 deletions code/frameworks/react-webpack5/src/typings.d.ts

This file was deleted.