diff --git a/code/renderers/react/src/docs/jsxDecorator.test.tsx b/code/renderers/react/src/docs/jsxDecorator.test.tsx index dbf6e53ffe31..57b1f3d4f61e 100644 --- a/code/renderers/react/src/docs/jsxDecorator.test.tsx +++ b/code/renderers/react/src/docs/jsxDecorator.test.tsx @@ -229,22 +229,6 @@ describe('jsxDecorator', () => { expect(mockChannel.emit).not.toHaveBeenCalled(); }); - // This is deprecated, but still test it - it('allows the snippet output to be modified by onBeforeRender', async () => { - const storyFn = (args: any) =>
args story
; - const onBeforeRender = (dom: string) => `

${dom}

`; - const jsx = { onBeforeRender }; - const context = makeContext('args', { __isArgsStory: true, jsx }, {}); - jsxDecorator(storyFn, context); - await new Promise((r) => setTimeout(r, 0)); - - expect(mockChannel.emit).toHaveBeenCalledWith( - SNIPPET_RENDERED, - 'jsx-test--args', - '

\n args story\n

' - ); - }); - it('allows the snippet output to be modified by transformSource', async () => { const storyFn = (args: any) =>
args story
; const transformSource = (dom: string) => `

${dom}

`; diff --git a/code/renderers/react/src/docs/jsxDecorator.tsx b/code/renderers/react/src/docs/jsxDecorator.tsx index 64bed62bfd74..343c30de9d95 100644 --- a/code/renderers/react/src/docs/jsxDecorator.tsx +++ b/code/renderers/react/src/docs/jsxDecorator.tsx @@ -1,8 +1,6 @@ /* eslint-disable no-underscore-dangle */ import React, { createElement, ReactElement } from 'react'; import reactElementToJSXString, { Options } from 'react-element-to-jsx-string'; -import { dedent } from 'ts-dedent'; -import deprecate from 'util-deprecate'; import { addons, useEffect } from '@storybook/addons'; import { StoryContext, ArgsStoryFn, PartialStoryFn } from '@storybook/csf'; @@ -22,30 +20,10 @@ type JSXOptions = Options & { enableBeautify?: boolean; /** Override the display name used for a component */ displayName?: string | Options['displayName']; - /** Deprecated: A function ran after the story is rendered */ - onBeforeRender?(dom: string): string; - /** A function ran after a story is rendered (prefer this over `onBeforeRender`) */ + /** A function ran after a story is rendered */ transformSource?(dom: string, context?: StoryContext): string; }; -/** Run the user supplied onBeforeRender function if it exists */ -const applyBeforeRender = (domString: string, options: JSXOptions) => { - if (typeof options.onBeforeRender !== 'function') { - return domString; - } - - const deprecatedOnBeforeRender = deprecate( - options.onBeforeRender, - dedent` - StoryFn.parameters.jsx.onBeforeRender was deprecated. - Prefer StoryFn.parameters.jsx.transformSource instead. - See https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-onbeforerender for details. - ` - ); - - return deprecatedOnBeforeRender(domString); -}; - /** Run the user supplied transformSource function if it exists */ const applyTransformSource = ( domString: string, @@ -127,7 +105,7 @@ export const renderJsx = (code: React.ReactElement, options: JSXOptions) => { ? reactElementToJSXString : // @ts-expect-error (Converted from ts-ignore) reactElementToJSXString.default; - let string = applyBeforeRender(toJSXString(child, opts as Options), options); + let string: string = toJSXString(child, opts as Options); if (string.indexOf('"') > -1) { const matches = string.match(/\S+=\\"([^"]*)\\"/g);