MCPcopy
hub / github.com/facebook/react / renderFragment

Function renderFragment

packages/react-server/src/ReactFlightServer.js:1839–1916  ·  view source on GitHub ↗
(
  request: Request,
  task: Task,
  children: $ReadOnlyArray<ReactClientValue>,
)

Source from the content-addressed store, hash-verified

1837}
1838
1839function renderFragment(
1840 request: Request,
1841 task: Task,
1842 children: $ReadOnlyArray<ReactClientValue>,
1843): ReactJSONValue {
1844 if (__DEV__) {
1845 for (let i = 0; i < children.length; i++) {
1846 const child = children[i];
1847 if (
1848 child !== null &&
1849 typeof child === 'object' &&
1850 child.$$typeof === REACT_ELEMENT_TYPE
1851 ) {
1852 const element: ReactElement = (child: any);
1853 if (element.key === null && !element._store.validated) {
1854 element._store.validated = 2;
1855 }
1856 }
1857 }
1858 }
1859
1860 if (task.keyPath !== null) {
1861 // We have a Server Component that specifies a key but we're now splitting
1862 // the tree using a fragment.
1863 const fragment = __DEV__
1864 ? [
1865 REACT_ELEMENT_TYPE,
1866 REACT_FRAGMENT_TYPE,
1867 task.keyPath,
1868 {children},
1869 null,
1870 null,
1871 0,
1872 ]
1873 : [REACT_ELEMENT_TYPE, REACT_FRAGMENT_TYPE, task.keyPath, {children}];
1874 if (!task.implicitSlot) {
1875 // If this was keyed inside a set. I.e. the outer Server Component was keyed
1876 // then we need to handle reorders of the whole set. To do this we need to wrap
1877 // this array in a keyed Fragment.
1878 return fragment;
1879 }
1880 // If the outer Server Component was implicit but then an inner one had a key
1881 // we don't actually need to be able to move the whole set around. It'll always be
1882 // in an implicit slot. The key only exists to be able to reset the state of the
1883 // children. We could achieve the same effect by passing on the keyPath to the next
1884 // set of components inside the fragment. This would also allow a keyless fragment
1885 // reconcile against a single child.
1886 // Unfortunately because of JSON.stringify, we can't call the recursive loop for
1887 // each child within this context because we can't return a set with already resolved
1888 // values. E.g. a string would get double encoded. Returning would pop the context.
1889 // So instead, we wrap it with an unkeyed fragment and inner keyed fragment.
1890 return [fragment];
1891 }
1892 // Since we're yielding here, that implicitly resets the keyPath context on the
1893 // way up. Which is what we want since we've consumed it. If this changes to
1894 // be recursive serialization, we need to reset the keyPath and implicitSlot,
1895 // before recursing here.
1896 if (__DEV__) {

Callers 1

renderModelDestructiveFunction · 0.85

Calls 2

outlineTaskFunction · 0.85
forwardDebugInfoFunction · 0.85

Tested by

no test coverage detected