vite-plugin-storybook-nextjs 3.2.5 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4925,6 +4925,10 @@ var getAlias2 = (env) => ({
4925
4925
  "router",
4926
4926
  env
4927
4927
  ),
4928
+ "next/link": getEntryPoint3("link", env),
4929
+ "@storybook/nextjs/link.mock": getEntryPoint3("link", env),
4930
+ "@storybook/nextjs-vite/link.mock": getEntryPoint3("link", env),
4931
+ "@storybook/experimental-nextjs-vite/link.mock": getEntryPoint3("link", env),
4928
4932
  "next/cache": getEntryPoint3("cache", env),
4929
4933
  "@storybook/nextjs/cache.mock": getEntryPoint3("cache", env),
4930
4934
  "@storybook/nextjs-vite/cache.mock": getEntryPoint3("cache", env),
@@ -5076,7 +5080,16 @@ function VitePlugin({
5076
5080
  // https://github.com/vitejs/vite/issues/16293
5077
5081
  "next > styled-jsx/style",
5078
5082
  ...nextConfig.compiler?.emotion ? ["@emotion/react/jsx-dev-runtime"] : [],
5079
- ...isNext16orNewer ? [] : ["next/config"]
5083
+ ...isNext16orNewer ? [] : ["next/config"],
5084
+ // Next.js 16 ships internal re-export chains that Vite's esbuild
5085
+ // pre-bundler fails to resolve in dev mode, causing missing exports
5086
+ // like ServerInsertedHTMLContext and RedirectStatusCode. Forcing
5087
+ // these modules to be pre-bundled fixes the resolution.
5088
+ // See: https://github.com/storybookjs/storybook/issues/34688
5089
+ ...isNext16orNewer ? [
5090
+ "next/navigation",
5091
+ "next/dist/client/components/redirect-error"
5092
+ ] : []
5080
5093
  ]
5081
5094
  },
5082
5095
  test: {
package/dist/index.js CHANGED
@@ -4892,6 +4892,10 @@ var getAlias2 = (env) => ({
4892
4892
  "router",
4893
4893
  env
4894
4894
  ),
4895
+ "next/link": getEntryPoint3("link", env),
4896
+ "@storybook/nextjs/link.mock": getEntryPoint3("link", env),
4897
+ "@storybook/nextjs-vite/link.mock": getEntryPoint3("link", env),
4898
+ "@storybook/experimental-nextjs-vite/link.mock": getEntryPoint3("link", env),
4895
4899
  "next/cache": getEntryPoint3("cache", env),
4896
4900
  "@storybook/nextjs/cache.mock": getEntryPoint3("cache", env),
4897
4901
  "@storybook/nextjs-vite/cache.mock": getEntryPoint3("cache", env),
@@ -5043,7 +5047,16 @@ function VitePlugin({
5043
5047
  // https://github.com/vitejs/vite/issues/16293
5044
5048
  "next > styled-jsx/style",
5045
5049
  ...nextConfig.compiler?.emotion ? ["@emotion/react/jsx-dev-runtime"] : [],
5046
- ...isNext16orNewer ? [] : ["next/config"]
5050
+ ...isNext16orNewer ? [] : ["next/config"],
5051
+ // Next.js 16 ships internal re-export chains that Vite's esbuild
5052
+ // pre-bundler fails to resolve in dev mode, causing missing exports
5053
+ // like ServerInsertedHTMLContext and RedirectStatusCode. Forcing
5054
+ // these modules to be pre-bundled fixes the resolution.
5055
+ // See: https://github.com/storybookjs/storybook/issues/34688
5056
+ ...isNext16orNewer ? [
5057
+ "next/navigation",
5058
+ "next/dist/client/components/redirect-error"
5059
+ ] : []
5047
5060
  ]
5048
5061
  },
5049
5062
  test: {
@@ -1982,6 +1982,10 @@ var getAlias2 = (env) => ({
1982
1982
  "router",
1983
1983
  env
1984
1984
  ),
1985
+ "next/link": getEntryPoint3("link", env),
1986
+ "@storybook/nextjs/link.mock": getEntryPoint3("link", env),
1987
+ "@storybook/nextjs-vite/link.mock": getEntryPoint3("link", env),
1988
+ "@storybook/experimental-nextjs-vite/link.mock": getEntryPoint3("link", env),
1985
1989
  "next/cache": getEntryPoint3("cache", env),
1986
1990
  "@storybook/nextjs/cache.mock": getEntryPoint3("cache", env),
1987
1991
  "@storybook/nextjs-vite/cache.mock": getEntryPoint3("cache", env),
@@ -1975,6 +1975,10 @@ var getAlias2 = (env) => ({
1975
1975
  "router",
1976
1976
  env
1977
1977
  ),
1978
+ "next/link": getEntryPoint3("link", env),
1979
+ "@storybook/nextjs/link.mock": getEntryPoint3("link", env),
1980
+ "@storybook/nextjs-vite/link.mock": getEntryPoint3("link", env),
1981
+ "@storybook/experimental-nextjs-vite/link.mock": getEntryPoint3("link", env),
1978
1982
  "next/cache": getEntryPoint3("cache", env),
1979
1983
  "@storybook/nextjs/cache.mock": getEntryPoint3("cache", env),
1980
1984
  "@storybook/nextjs-vite/cache.mock": getEntryPoint3("cache", env),
@@ -31,8 +31,9 @@ var NextImageNamespace__namespace = /*#__PURE__*/_interopNamespace(NextImageName
31
31
  var React__default = /*#__PURE__*/_interopDefault(React);
32
32
 
33
33
  // src/plugins/next-image/alias/next-image.tsx
34
- var OriginalNextImage = NextImageNamespace__namespace.default;
35
- var { getImageProps: originalGetImageProps } = NextImageNamespace__namespace;
34
+ var _raw = NextImageNamespace__namespace.default;
35
+ var OriginalNextImage = typeof _raw === "object" && _raw !== null && "__esModule" in _raw ? _raw.default : _raw;
36
+ var originalGetImageProps = NextImageNamespace__namespace.getImageProps ?? (typeof _raw === "object" && _raw !== null && "getImageProps" in _raw ? _raw.getImageProps : void 0);
36
37
  var MockedNextImage = React__default.default.forwardRef(({ loader, ...props }, ref) => {
37
38
  const imageParameters = React__default.default.useContext(imageContext.ImageContext);
38
39
  return /* @__PURE__ */ React__default.default.createElement(
@@ -46,8 +47,8 @@ var MockedNextImage = React__default.default.forwardRef(({ loader, ...props }, r
46
47
  );
47
48
  });
48
49
  MockedNextImage.displayName = "NextImage";
49
- var getImageProps = (props) => originalGetImageProps?.({ loader: defaultLoader.defaultLoader, ...props });
50
+ var getImageProps2 = (props) => originalGetImageProps?.({ loader: defaultLoader.defaultLoader, ...props });
50
51
  var next_image_default = MockedNextImage;
51
52
 
52
53
  exports.default = next_image_default;
53
- exports.getImageProps = getImageProps;
54
+ exports.getImageProps = getImageProps2;
@@ -2,7 +2,7 @@ import * as next_dist_shared_lib_get_img_props from 'next/dist/shared/lib/get-im
2
2
  import * as _NextImage from 'next/image';
3
3
  import React__default from 'next/dist/compiled/react';
4
4
 
5
- declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "srcSet" | "ref" | "alt" | "width" | "height" | "loading"> & {
5
+ declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "width" | "srcSet" | "ref" | "alt" | "height" | "loading"> & {
6
6
  src: string | next_dist_shared_lib_get_img_props.StaticImport;
7
7
  alt: string;
8
8
  width?: number | `${number}`;
@@ -2,7 +2,7 @@ import * as next_dist_shared_lib_get_img_props from 'next/dist/shared/lib/get-im
2
2
  import * as _NextImage from 'next/image';
3
3
  import React__default from 'next/dist/compiled/react';
4
4
 
5
- declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "srcSet" | "ref" | "alt" | "width" | "height" | "loading"> & {
5
+ declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "width" | "srcSet" | "ref" | "alt" | "height" | "loading"> & {
6
6
  src: string | next_dist_shared_lib_get_img_props.StaticImport;
7
7
  alt: string;
8
8
  width?: number | `${number}`;
@@ -4,8 +4,9 @@ import { ImageContext } from 'sb-original/image-context';
4
4
  import React from 'next/dist/compiled/react';
5
5
 
6
6
  // src/plugins/next-image/alias/next-image.tsx
7
- var OriginalNextImage = NextImageNamespace.default;
8
- var { getImageProps: originalGetImageProps } = NextImageNamespace;
7
+ var _raw = NextImageNamespace.default;
8
+ var OriginalNextImage = typeof _raw === "object" && _raw !== null && "__esModule" in _raw ? _raw.default : _raw;
9
+ var originalGetImageProps = NextImageNamespace.getImageProps ?? (typeof _raw === "object" && _raw !== null && "getImageProps" in _raw ? _raw.getImageProps : void 0);
9
10
  var MockedNextImage = React.forwardRef(({ loader, ...props }, ref) => {
10
11
  const imageParameters = React.useContext(ImageContext);
11
12
  return /* @__PURE__ */ React.createElement(
@@ -19,7 +20,7 @@ var MockedNextImage = React.forwardRef(({ loader, ...props }, ref) => {
19
20
  );
20
21
  });
21
22
  MockedNextImage.displayName = "NextImage";
22
- var getImageProps = (props) => originalGetImageProps?.({ loader: defaultLoader, ...props });
23
+ var getImageProps2 = (props) => originalGetImageProps?.({ loader: defaultLoader, ...props });
23
24
  var next_image_default = MockedNextImage;
24
25
 
25
- export { next_image_default as default, getImageProps };
26
+ export { next_image_default as default, getImageProps2 as getImageProps };
@@ -1,20 +1,40 @@
1
1
  'use strict';
2
2
 
3
- var OriginalNextLegacyImage = require('next/legacy/image');
3
+ var _NextLegacyImageNamespace = require('next/legacy/image');
4
4
  var defaultLoader = require('sb-original/default-loader');
5
5
  var imageContext = require('sb-original/image-context');
6
6
  var React = require('next/dist/compiled/react');
7
7
 
8
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
9
 
10
- var OriginalNextLegacyImage__default = /*#__PURE__*/_interopDefault(OriginalNextLegacyImage);
10
+ function _interopNamespace(e) {
11
+ if (e && e.__esModule) return e;
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n.default = e;
25
+ return Object.freeze(n);
26
+ }
27
+
28
+ var _NextLegacyImageNamespace__namespace = /*#__PURE__*/_interopNamespace(_NextLegacyImageNamespace);
11
29
  var React__default = /*#__PURE__*/_interopDefault(React);
12
30
 
13
31
  // src/plugins/next-image/alias/next-legacy-image.tsx
32
+ var _rawLegacy = _NextLegacyImageNamespace__namespace.default;
33
+ var OriginalNextLegacyImage = typeof _rawLegacy === "object" && _rawLegacy !== null && "__esModule" in _rawLegacy ? _rawLegacy.default : _rawLegacy;
14
34
  function NextLegacyImage({ loader, ...props }) {
15
35
  const imageParameters = React__default.default.useContext(imageContext.ImageContext);
16
36
  return /* @__PURE__ */ React__default.default.createElement(
17
- OriginalNextLegacyImage__default.default,
37
+ OriginalNextLegacyImage,
18
38
  {
19
39
  ...imageParameters,
20
40
  ...props,
@@ -1,9 +1,11 @@
1
- import OriginalNextLegacyImage from 'next/legacy/image';
1
+ import * as _NextLegacyImageNamespace from 'next/legacy/image';
2
2
  import { defaultLoader } from 'sb-original/default-loader';
3
3
  import { ImageContext } from 'sb-original/image-context';
4
4
  import React from 'next/dist/compiled/react';
5
5
 
6
6
  // src/plugins/next-image/alias/next-legacy-image.tsx
7
+ var _rawLegacy = _NextLegacyImageNamespace.default;
8
+ var OriginalNextLegacyImage = typeof _rawLegacy === "object" && _rawLegacy !== null && "__esModule" in _rawLegacy ? _rawLegacy.default : _rawLegacy;
7
9
  function NextLegacyImage({ loader, ...props }) {
8
10
  const imageParameters = React.useContext(ImageContext);
9
11
  return /* @__PURE__ */ React.createElement(
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var test = require('storybook/test');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var React__default = /*#__PURE__*/_interopDefault(React);
11
+
12
+ // src/plugins/next-mocks/alias/link/index.tsx
13
+ var linkAction = test.fn().mockName("next/link::Link");
14
+ var MockLink = React__default.default.forwardRef(
15
+ function MockLink2({
16
+ href,
17
+ as: _as,
18
+ replace,
19
+ scroll,
20
+ shallow,
21
+ prefetch,
22
+ passHref,
23
+ legacyBehavior,
24
+ locale,
25
+ onClick,
26
+ children,
27
+ ...rest
28
+ }, ref) {
29
+ const hrefString = typeof href === "object" ? `${href.pathname || ""}${href.query ? `?${new URLSearchParams(
30
+ href.query
31
+ ).toString()}` : ""}${href.hash || ""}` : href;
32
+ const handleClick = (e) => {
33
+ e.preventDefault();
34
+ onClick?.(e);
35
+ linkAction(hrefString, { replace, scroll, shallow, prefetch, locale });
36
+ };
37
+ if (legacyBehavior) {
38
+ const child = React__default.default.Children.only(children);
39
+ const childProps = {
40
+ ref,
41
+ onClick: (e) => {
42
+ e.preventDefault();
43
+ if (child.props && typeof child.props.onClick === "function") {
44
+ child.props.onClick(e);
45
+ }
46
+ linkAction(hrefString, {
47
+ replace,
48
+ scroll,
49
+ shallow,
50
+ prefetch,
51
+ locale
52
+ });
53
+ },
54
+ ...rest
55
+ };
56
+ if (passHref || child.type === "a" && !("href" in (child.props || {}))) {
57
+ childProps.href = hrefString;
58
+ }
59
+ return React__default.default.cloneElement(child, childProps);
60
+ }
61
+ return /* @__PURE__ */ React__default.default.createElement("a", { ref, href: hrefString, onClick: handleClick, ...rest }, children);
62
+ }
63
+ );
64
+ MockLink.displayName = "NextLink";
65
+ var link_default = MockLink;
66
+ var useLinkStatus = test.fn(() => ({
67
+ pending: false
68
+ })).mockName("next/link::useLinkStatus");
69
+
70
+ exports.Link = MockLink;
71
+ exports.default = link_default;
72
+ exports.useLinkStatus = useLinkStatus;
@@ -0,0 +1,11 @@
1
+ import * as storybook_test from 'storybook/test';
2
+ import { LinkProps } from 'next/link';
3
+ import React from 'react';
4
+
5
+ declare const MockLink: React.ForwardRefExoticComponent<LinkProps<any> & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof LinkProps<any>> & {
6
+ children?: React.ReactNode;
7
+ } & React.RefAttributes<HTMLAnchorElement>>;
8
+
9
+ declare const useLinkStatus: storybook_test.Mock<(...args: any[]) => any>;
10
+
11
+ export { MockLink as Link, MockLink as default, useLinkStatus };
@@ -0,0 +1,11 @@
1
+ import * as storybook_test from 'storybook/test';
2
+ import { LinkProps } from 'next/link';
3
+ import React from 'react';
4
+
5
+ declare const MockLink: React.ForwardRefExoticComponent<LinkProps<any> & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof LinkProps<any>> & {
6
+ children?: React.ReactNode;
7
+ } & React.RefAttributes<HTMLAnchorElement>>;
8
+
9
+ declare const useLinkStatus: storybook_test.Mock<(...args: any[]) => any>;
10
+
11
+ export { MockLink as Link, MockLink as default, useLinkStatus };
@@ -0,0 +1,62 @@
1
+ import React from 'react';
2
+ import { fn } from 'storybook/test';
3
+
4
+ // src/plugins/next-mocks/alias/link/index.tsx
5
+ var linkAction = fn().mockName("next/link::Link");
6
+ var MockLink = React.forwardRef(
7
+ function MockLink2({
8
+ href,
9
+ as: _as,
10
+ replace,
11
+ scroll,
12
+ shallow,
13
+ prefetch,
14
+ passHref,
15
+ legacyBehavior,
16
+ locale,
17
+ onClick,
18
+ children,
19
+ ...rest
20
+ }, ref) {
21
+ const hrefString = typeof href === "object" ? `${href.pathname || ""}${href.query ? `?${new URLSearchParams(
22
+ href.query
23
+ ).toString()}` : ""}${href.hash || ""}` : href;
24
+ const handleClick = (e) => {
25
+ e.preventDefault();
26
+ onClick?.(e);
27
+ linkAction(hrefString, { replace, scroll, shallow, prefetch, locale });
28
+ };
29
+ if (legacyBehavior) {
30
+ const child = React.Children.only(children);
31
+ const childProps = {
32
+ ref,
33
+ onClick: (e) => {
34
+ e.preventDefault();
35
+ if (child.props && typeof child.props.onClick === "function") {
36
+ child.props.onClick(e);
37
+ }
38
+ linkAction(hrefString, {
39
+ replace,
40
+ scroll,
41
+ shallow,
42
+ prefetch,
43
+ locale
44
+ });
45
+ },
46
+ ...rest
47
+ };
48
+ if (passHref || child.type === "a" && !("href" in (child.props || {}))) {
49
+ childProps.href = hrefString;
50
+ }
51
+ return React.cloneElement(child, childProps);
52
+ }
53
+ return /* @__PURE__ */ React.createElement("a", { ref, href: hrefString, onClick: handleClick, ...rest }, children);
54
+ }
55
+ );
56
+ MockLink.displayName = "NextLink";
57
+ var link_default = MockLink;
58
+ var useLinkStatus = fn(() => ({
59
+ pending: false
60
+ })).mockName("next/link::useLinkStatus");
61
+
62
+ export { MockLink as Link, link_default as default, useLinkStatus };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-storybook-nextjs",
3
- "version": "3.2.5",
3
+ "version": "3.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/storybookjs/vite-plugin-storybook-nextjs.git"
@@ -38,6 +38,7 @@
38
38
  "./browser/mocks/navigation": "./dist/plugins/next-mocks/alias/navigation/index.js",
39
39
  "./browser/mocks/headers": "./dist/plugins/next-mocks/alias/headers/index.js",
40
40
  "./browser/mocks/router": "./dist/plugins/next-mocks/alias/router/index.js",
41
+ "./browser/mocks/link": "./dist/plugins/next-mocks/alias/link/index.js",
41
42
  "./browser/mocks/server-only": "./dist/plugins/next-mocks/alias/rsc/server-only.js",
42
43
  "./browser/mocks/dynamic": "./dist/plugins/next-mocks/alias/dynamic/index.js",
43
44
  "./browser/mocks/image": "./dist/plugins/next-image/alias/next-image.js",
@@ -49,6 +50,7 @@
49
50
  "./node/mocks/navigation": "./dist/plugins/next-mocks/alias/navigation/index.cjs",
50
51
  "./node/mocks/headers": "./dist/plugins/next-mocks/alias/headers/index.cjs",
51
52
  "./node/mocks/router": "./dist/plugins/next-mocks/alias/router/index.cjs",
53
+ "./node/mocks/link": "./dist/plugins/next-mocks/alias/link/index.cjs",
52
54
  "./node/mocks/server-only": "./dist/plugins/next-mocks/alias/rsc/server-only.cjs",
53
55
  "./node/mocks/dynamic": "./dist/plugins/next-mocks/alias/dynamic/index.cjs",
54
56
  "./node/mocks/image": "./dist/plugins/next-image/alias/next-image.cjs",