Repository: withastro/astro
File: packages/integrations/react/server.js (JavaScript)

Code before:
	if (children && opts.experimentalReactChildren) {
		attrs['data-react-children'] = true;
		const convert = await import('./vnode-children.js').then((mod) => mod.default);
		newProps.children = convert(children);
	} else if (newChildren != null) {
		newProps.children = React.createElement(StaticHtml, {
			hydrate: needsHydration(metadata),
			value: newChildren,
		});
	}
	const formState = this ? await getFormState(this) : undefined;
	if (formState) {
		attrs['data-action-result'] = JSON.stringify(formState[0]);
		attrs['data-action-key'] = formState[1];
		attrs['data-action-name'] = formState[2];
	}
	const vnode = React.createElement(Component, newProps);
	const renderOptions = {
		identifierPrefix: prefix,
		formState,
	};
	let html;
	if (opts.experimentalDisableStreaming) {
		html = ReactDOM.renderToString(vnode);
	}
	if ('renderToReadableStream' in ReactDOM) {
		html = await renderToReadableStreamAsync(vnode, renderOptions);
	} else {
		html = await renderToPipeableStreamAsync(vnode, renderOptions);
	}
	return { html, attrs };
}

/**
 * @returns {Promise<[actionResult: any, actionKey: string, actionName: string] | undefined>}
 */
async function getFormState({ result }) {
	const { request, actionResult } = result;

	if (!actionResult) return undefined;
	if (!isFormRequest(request.headers.get('content-type'))) return undefined;

	const { searchParams } = new URL(request.url);
	const formData = await request.clone().formData();
	/**
	 * The key generated by React to identify each `useActionState()` call.
	 * @example "k511f74df5a35d32e7cf266450d85cb6c"
	 */
	const actionKey = formData.get('$ACTION_KEY')?.toString();
	/**
	 * The action name returned by an action's `toString()` property.

Review comment (suggestion):
Should this be an else if?
```suggestion
	else if ('renderToReadableStream' in ReactDOM) {
```

Code after:
	if (children && opts.experimentalReactChildren) {
		attrs['data-react-children'] = true;
		const convert = await import('./vnode-children.js').then((mod) => mod.default);
		newProps.children = convert(children);
	} else if (newChildren != null) {
		newProps.children = React.createElement(StaticHtml, {
			hydrate: needsHydration(metadata),
			value: newChildren,
		});
	}
	const formState = this ? await getFormState(this) : undefined;
	if (formState) {
		attrs['data-action-result'] = JSON.stringify(formState[0]);
		attrs['data-action-key'] = formState[1];
		attrs['data-action-name'] = formState[2];
	}
	const vnode = React.createElement(Component, newProps);
	const renderOptions = {
		identifierPrefix: prefix,
		formState,
	};
	let html;
	if (opts.experimentalDisableStreaming) {
		html = ReactDOM.renderToString(vnode);
	} else if ('renderToReadableStream' in ReactDOM) {
		html = await renderToReadableStreamAsync(vnode, renderOptions);
	} else {
		html = await renderToPipeableStreamAsync(vnode, renderOptions);
	}
	return { html, attrs };
}

/**
 * @returns {Promise<[actionResult: any, actionKey: string, actionName: string] | undefined>}
 */
async function getFormState({ result }) {
	const { request, actionResult } = result;

	if (!actionResult) return undefined;
	if (!isFormRequest(request.headers.get('content-type'))) return undefined;

	const { searchParams } = new URL(request.url);
	const formData = await request.clone().formData();
	/**
	 * The key generated by React to identify each `useActionState()` call.
	 * @example "k511f74df5a35d32e7cf266450d85cb6c"
	 */
	const actionKey = formData.get('$ACTION_KEY')?.toString();
	/**
	 * The action name returned by an action's `toString()` property.
	 * This matches the endpoint path.