react-cosmos-renderer
Advanced tools
Comparing version 6.1.2-canary.5da46eb.0 to 6.1.2-canary.71267f3.0
import React from 'react'; | ||
import { isElement } from 'react-is'; | ||
export function createFixtureNode(fixture) { | ||
// Warning: In a React Server Components setup this function is called on the | ||
// server. When a fixture module uses the 'use client' directive, the fixture | ||
// arg received here will be a function wrapper regardless of the fixture | ||
// module contents. In this scenario, the fixture module will be automatically | ||
// rendered on the client side, where React expects a component default export. | ||
// export will be a Promise wrapper (imbued with magical properties methinks). | ||
// This results in the following limitation: In a React Server Components | ||
// setup, Client fixtures have to export a single function component. They | ||
// can't be multi fixtures and they can't export React elements directly. | ||
return isFunctionFixture(fixture) ? (React.createElement(FixtureElement, { Component: fixture })) : (fixture); | ||
return isNodeFixture(fixture) ? (fixture) : (React.createElement(FixtureElement, { Component: fixture })); | ||
} | ||
function isFunctionFixture(fixture) { | ||
return typeof fixture === 'function'; | ||
function isNodeFixture(fixture) { | ||
// If you're curious what the exact type of ReactNode is: | ||
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6fc4839a810335dee15374e6bc82dbbc2bbdff58/types/react/index.d.ts#L478-L489 | ||
return (fixture === undefined || | ||
fixture === null || | ||
typeof fixture === 'string' || | ||
typeof fixture === 'number' || | ||
typeof fixture === 'boolean' || | ||
Array.isArray(fixture) || | ||
// If you're curious what isElement checks: | ||
// https://github.com/facebook/react/blob/1b0132c05acabae5aebd32c2cadddfb16bda70bc/packages/react-is/src/ReactIs.js#L108-L114 | ||
isElement(fixture)); | ||
} | ||
@@ -16,0 +25,0 @@ function FixtureElement({ Component }) { |
{ | ||
"name": "react-cosmos-renderer", | ||
"version": "6.1.2-canary.5da46eb.0+5da46eb", | ||
"version": "6.1.2-canary.71267f3.0+71267f3", | ||
"description": "React Cosmos Renderer", | ||
@@ -15,6 +15,6 @@ "repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-renderer", | ||
"lodash-es": "4.17.21", | ||
"react-cosmos-core": "6.1.2-canary.5da46eb.0+5da46eb", | ||
"react-cosmos-core": "6.1.2-canary.71267f3.0+71267f3", | ||
"react-is": "18.2.0" | ||
}, | ||
"gitHead": "5da46eb86dab5ebfb0d2b6a8273ca10a32deda2d" | ||
"gitHead": "71267f34230c703f89e58b12a87a25572c9cd5d8" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
73064
1546