react-cosmos-renderer 6.0.0-alpha.19 → 6.0.0-alpha.20

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.
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
- import { ReactDecorator, RendererParams, UserModuleWrappers } from 'react-cosmos-core';
2
+ import { FixtureId, ReactDecorator, UserModuleWrappers } from 'react-cosmos-core';
3
3
  type Props = {
4
- params: RendererParams;
4
+ fixtureId: FixtureId | null;
5
5
  moduleWrappers: UserModuleWrappers;
6
6
  globalDecorators?: ReactDecorator[];
7
7
  renderMessage?: (msg: string) => React.ReactElement;
8
8
  };
9
- export declare function ServerFixtureLoader({ params, moduleWrappers, globalDecorators, renderMessage, }: Props): JSX.Element;
9
+ export declare function ServerFixtureLoader({ fixtureId, moduleWrappers, globalDecorators, renderMessage, }: Props): JSX.Element;
10
10
  export {};
@@ -4,12 +4,17 @@ import { AsyncModuleLoader } from '../moduleLoaders/AsyncModuleLoader.js';
4
4
  import { FixtureLoaderConnect } from './FixtureLoaderConnect.js';
5
5
  import { ServerFixtureChangeListener } from './ServerFixtureChangeListener.js';
6
6
  import { defaultRenderMessage } from './defaultRenderMessage.js';
7
- export function ServerFixtureLoader({ params, moduleWrappers, globalDecorators, renderMessage = defaultRenderMessage, }) {
8
- const { fixtureId = null, key = 0 } = params;
7
+ export function ServerFixtureLoader({ fixtureId, moduleWrappers, globalDecorators, renderMessage = defaultRenderMessage, }) {
9
8
  const fixtureSelection = fixtureId && {
10
9
  fixtureId,
11
10
  initialFixtureState: {},
12
- renderKey: key,
11
+ // Search fixture loader is meant to work with Next.js build-time static
12
+ // generation. Its props will be driven by finite URL segment params and not
13
+ // query strings, which are inherently dynamic. This means we can't receive
14
+ // an incrementing renderKey here. Instead, we'll rely solely on the fixture
15
+ // ID as the fixture render key and will not support refreshing the current
16
+ // fixture by selecting it again.
17
+ renderKey: 0,
13
18
  };
14
19
  return (React.createElement(ServerFixtureChangeListener, null,
15
20
  React.createElement(FixtureLoaderConnect, { moduleWrappers: moduleWrappers, fixtureSelection: fixtureSelection, renderMessage: renderMessage, renderFixture: selection => (
@@ -1,13 +1,14 @@
1
1
  import React from 'react';
2
- import { getFixtureFromExport, getFixtureItemFromExport, } from 'react-cosmos-core';
2
+ import { getFixtureFromExport, getFixtureItemFromExport, stringifyFixtureId, } from 'react-cosmos-core';
3
3
  import { DecoratedFixture } from './DecoratedFixture.js';
4
4
  import { FixtureProvider } from './FixtureProvider.js';
5
5
  export function FixtureModule({ fixtureModule, decoratorModules, globalDecorators, fixtureId, initialFixtureState, renderKey, lazy, renderMessage, }) {
6
6
  const fixtureItem = React.useMemo(() => getFixtureItemFromExport(fixtureModule.default), [fixtureModule.default]);
7
+ const fixtureKey = React.useMemo(() => `${stringifyFixtureId(fixtureId)}-${renderKey}`, [fixtureId, renderKey]);
7
8
  const fixture = getFixtureFromExport(fixtureModule.default, fixtureId.name);
8
9
  if (typeof fixture === 'undefined') {
9
10
  return renderMessage(`Invalid fixture name: ${fixtureId.name}`);
10
11
  }
11
- return (React.createElement(FixtureProvider, { key: renderKey, fixtureId: fixtureId, initialFixtureState: initialFixtureState, fixtureItem: fixtureItem, lazy: lazy },
12
+ return (React.createElement(FixtureProvider, { key: fixtureKey, fixtureId: fixtureId, initialFixtureState: initialFixtureState, fixtureItem: fixtureItem, lazy: lazy },
12
13
  React.createElement(DecoratedFixture, { fixture: fixture, userDecoratorModules: decoratorModules, globalDecorators: globalDecorators })));
13
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-cosmos-renderer",
3
- "version": "6.0.0-alpha.19",
3
+ "version": "6.0.0-alpha.20",
4
4
  "description": "React Cosmos Renderer",
5
5
  "repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-renderer",
6
6
  "license": "MIT",
@@ -12,8 +12,8 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "lodash-es": "^4.17.21",
15
- "react-cosmos-core": "6.0.0-alpha.19",
15
+ "react-cosmos-core": "6.0.0-alpha.20",
16
16
  "react-is": "^18.2.0"
17
17
  },
18
- "gitHead": "e2ac66d70184f04b23853c3f57b2ec31c5684eb0"
18
+ "gitHead": "31201ce4185919b054f42b8f15b3e87033af4e69"
19
19
  }