mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Rename renderToMarkup to renderToHTML (#30689)
This commit is contained in:
@@ -25,7 +25,7 @@ export function prepareDestinationForModule(
|
||||
metadata: ClientReferenceMetadata,
|
||||
) {
|
||||
throw new Error(
|
||||
'renderToMarkup should not have emitted Client References. This is a bug in React.',
|
||||
'renderToHTML should not have emitted Client References. This is a bug in React.',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ export function resolveClientReference<T>(
|
||||
metadata: ClientReferenceMetadata,
|
||||
): ClientReference<T> {
|
||||
throw new Error(
|
||||
'renderToMarkup should not have emitted Client References. This is a bug in React.',
|
||||
'renderToHTML should not have emitted Client References. This is a bug in React.',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ export function resolveServerReference<T>(
|
||||
id: ServerReferenceId,
|
||||
): ClientReference<T> {
|
||||
throw new Error(
|
||||
'renderToMarkup should not have emitted Server References. This is a bug in React.',
|
||||
'renderToHTML should not have emitted Server References. This is a bug in React.',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ export function preloadModule<T>(
|
||||
|
||||
export function requireModule<T>(metadata: ClientReference<T>): T {
|
||||
throw new Error(
|
||||
'renderToMarkup should not have emitted Client References. This is a bug in React.',
|
||||
'renderToHTML should not have emitted Client References. This is a bug in React.',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,13 +11,13 @@ npm install react react-markup
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import { renderToMarkup } from 'react-markup';
|
||||
import { renderToHTML } from 'react-markup';
|
||||
import EmailTemplate from './my-email-template-component.js'
|
||||
|
||||
async function action(email, name) {
|
||||
"use server";
|
||||
// ... in your server, e.g. a Server Action...
|
||||
const htmlString = await renderToMarkup(<EmailTemplate name={name} />);
|
||||
const htmlString = await renderToHTML(<EmailTemplate name={name} />);
|
||||
// ... send e-mail using some e-mail provider
|
||||
await sendEmail({ to: email, contentType: 'text/html', body: htmlString });
|
||||
}
|
||||
|
||||
+2
-2
@@ -95,14 +95,14 @@ export function pushStartInstance(
|
||||
const propValue = props[propKey];
|
||||
if (propKey === 'ref' && propValue != null) {
|
||||
throw new Error(
|
||||
'Cannot pass ref in renderToMarkup because they will never be hydrated.',
|
||||
'Cannot pass ref in renderToHTML because they will never be hydrated.',
|
||||
);
|
||||
}
|
||||
if (typeof propValue === 'function') {
|
||||
throw new Error(
|
||||
'Cannot pass event handlers (' +
|
||||
propKey +
|
||||
') in renderToMarkup because ' +
|
||||
') in renderToHTML because ' +
|
||||
'the HTML will never be hydrated so they can never get called.',
|
||||
);
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ type MarkupOptions = {
|
||||
onError?: (error: mixed, errorInfo: ErrorInfo) => ?string,
|
||||
};
|
||||
|
||||
export function renderToMarkup(
|
||||
export function renderToHTML(
|
||||
children: ReactNodeList,
|
||||
options?: MarkupOptions,
|
||||
): Promise<string> {
|
||||
|
||||
+2
-2
@@ -71,11 +71,11 @@ type MarkupOptions = {
|
||||
|
||||
function noServerCallOrFormAction() {
|
||||
throw new Error(
|
||||
'renderToMarkup should not have emitted Server References. This is a bug in React.',
|
||||
'renderToHTML should not have emitted Server References. This is a bug in React.',
|
||||
);
|
||||
}
|
||||
|
||||
export function renderToMarkup(
|
||||
export function renderToHTML(
|
||||
children: ReactMarkupNodeList,
|
||||
options?: MarkupOptions,
|
||||
): Promise<string> {
|
||||
|
||||
@@ -43,7 +43,7 @@ if (!__EXPERIMENTAL__) {
|
||||
return <div>hello world</div>;
|
||||
}
|
||||
|
||||
const html = await ReactMarkup.renderToMarkup(<Component />);
|
||||
const html = await ReactMarkup.renderToHTML(<Component />);
|
||||
expect(html).toBe('<div>hello world</div>');
|
||||
});
|
||||
|
||||
@@ -52,14 +52,14 @@ if (!__EXPERIMENTAL__) {
|
||||
return <div>{'hello '.repeat(200)}world</div>;
|
||||
}
|
||||
|
||||
const html = await ReactMarkup.renderToMarkup(
|
||||
const html = await ReactMarkup.renderToHTML(
|
||||
React.createElement(Component),
|
||||
);
|
||||
expect(html).toBe('<div>' + ('hello '.repeat(200) + 'world') + '</div>');
|
||||
});
|
||||
|
||||
it('should prefix html tags with a doctype', async () => {
|
||||
const html = await ReactMarkup.renderToMarkup(
|
||||
const html = await ReactMarkup.renderToHTML(
|
||||
<html>
|
||||
<body>hello</body>
|
||||
</html>,
|
||||
@@ -76,7 +76,7 @@ if (!__EXPERIMENTAL__) {
|
||||
}
|
||||
|
||||
await expect(async () => {
|
||||
await ReactMarkup.renderToMarkup(<Component />);
|
||||
await ReactMarkup.renderToHTML(<Component />);
|
||||
}).rejects.toThrow();
|
||||
});
|
||||
|
||||
@@ -87,7 +87,7 @@ if (!__EXPERIMENTAL__) {
|
||||
}
|
||||
|
||||
await expect(async () => {
|
||||
await ReactMarkup.renderToMarkup(<Component />);
|
||||
await ReactMarkup.renderToHTML(<Component />);
|
||||
}).rejects.toThrow();
|
||||
});
|
||||
|
||||
@@ -100,7 +100,7 @@ if (!__EXPERIMENTAL__) {
|
||||
}
|
||||
|
||||
await expect(async () => {
|
||||
await ReactMarkup.renderToMarkup(<Component />);
|
||||
await ReactMarkup.renderToHTML(<Component />);
|
||||
}).rejects.toThrow();
|
||||
});
|
||||
|
||||
@@ -142,7 +142,7 @@ if (!__EXPERIMENTAL__) {
|
||||
);
|
||||
}
|
||||
|
||||
const html = await ReactMarkup.renderToMarkup(<Component />);
|
||||
const html = await ReactMarkup.renderToHTML(<Component />);
|
||||
const container = document.createElement('div');
|
||||
container.innerHTML = html;
|
||||
|
||||
@@ -176,7 +176,7 @@ if (!__EXPERIMENTAL__) {
|
||||
);
|
||||
}
|
||||
|
||||
const html = await ReactMarkup.renderToMarkup(<Component />);
|
||||
const html = await ReactMarkup.renderToHTML(<Component />);
|
||||
expect(html).toBe('<div>01</div>');
|
||||
});
|
||||
|
||||
@@ -199,7 +199,7 @@ if (!__EXPERIMENTAL__) {
|
||||
}
|
||||
|
||||
await expect(async () => {
|
||||
await ReactMarkup.renderToMarkup(
|
||||
await ReactMarkup.renderToHTML(
|
||||
<div>
|
||||
<Foo />
|
||||
</div>,
|
||||
|
||||
@@ -64,7 +64,7 @@ if (!__EXPERIMENTAL__) {
|
||||
return React.createElement('div', null, 'hello world');
|
||||
}
|
||||
|
||||
const html = await ReactMarkup.renderToMarkup(
|
||||
const html = await ReactMarkup.renderToHTML(
|
||||
React.createElement(Component),
|
||||
);
|
||||
expect(html).toBe('<div>hello world</div>');
|
||||
@@ -76,14 +76,14 @@ if (!__EXPERIMENTAL__) {
|
||||
return React.createElement('div', null, 'hello '.repeat(200) + 'world');
|
||||
}
|
||||
|
||||
const html = await ReactMarkup.renderToMarkup(
|
||||
const html = await ReactMarkup.renderToHTML(
|
||||
React.createElement(Component),
|
||||
);
|
||||
expect(html).toBe('<div>' + ('hello '.repeat(200) + 'world') + '</div>');
|
||||
});
|
||||
|
||||
it('should prefix html tags with a doctype', async () => {
|
||||
const html = await ReactMarkup.renderToMarkup(
|
||||
const html = await ReactMarkup.renderToHTML(
|
||||
// We can't use JSX because that's client-JSX in our tests.
|
||||
React.createElement(
|
||||
'html',
|
||||
@@ -104,7 +104,7 @@ if (!__EXPERIMENTAL__) {
|
||||
}
|
||||
|
||||
await expect(async () => {
|
||||
await ReactMarkup.renderToMarkup(React.createElement(Component));
|
||||
await ReactMarkup.renderToHTML(React.createElement(Component));
|
||||
}).rejects.toThrow();
|
||||
});
|
||||
|
||||
@@ -116,7 +116,7 @@ if (!__EXPERIMENTAL__) {
|
||||
}
|
||||
|
||||
await expect(async () => {
|
||||
await ReactMarkup.renderToMarkup(React.createElement(Component));
|
||||
await ReactMarkup.renderToHTML(React.createElement(Component));
|
||||
}).rejects.toThrow();
|
||||
});
|
||||
|
||||
@@ -130,7 +130,7 @@ if (!__EXPERIMENTAL__) {
|
||||
}
|
||||
|
||||
await expect(async () => {
|
||||
await ReactMarkup.renderToMarkup(React.createElement(Component));
|
||||
await ReactMarkup.renderToHTML(React.createElement(Component));
|
||||
}).rejects.toThrow();
|
||||
});
|
||||
|
||||
@@ -173,7 +173,7 @@ if (!__EXPERIMENTAL__) {
|
||||
);
|
||||
}
|
||||
|
||||
const html = await ReactMarkup.renderToMarkup(
|
||||
const html = await ReactMarkup.renderToHTML(
|
||||
React.createElement(Component),
|
||||
);
|
||||
const container = document.createElement('div');
|
||||
@@ -204,7 +204,7 @@ if (!__EXPERIMENTAL__) {
|
||||
return React.createElement('div', null, a, b);
|
||||
}
|
||||
|
||||
const html = await ReactMarkup.renderToMarkup(
|
||||
const html = await ReactMarkup.renderToHTML(
|
||||
React.createElement(Component),
|
||||
);
|
||||
expect(html).toBe('<div>00</div>');
|
||||
@@ -225,7 +225,7 @@ if (!__EXPERIMENTAL__) {
|
||||
}
|
||||
|
||||
await expect(async () => {
|
||||
await ReactMarkup.renderToMarkup(
|
||||
await ReactMarkup.renderToHTML(
|
||||
React.createElement('div', null, React.createElement(Foo)),
|
||||
{
|
||||
onError(error, errorInfo) {
|
||||
|
||||
+1
-1
@@ -804,7 +804,7 @@ function noop(): void {}
|
||||
|
||||
function clientHookNotSupported() {
|
||||
throw new Error(
|
||||
'Cannot use state or effect Hooks in renderToMarkup because ' +
|
||||
'Cannot use state or effect Hooks in renderToHTML because ' +
|
||||
'this component will never be hydrated.',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,9 +52,9 @@ export function getClientReferenceKey(
|
||||
reference: ClientReference<any>,
|
||||
): ClientReferenceKey {
|
||||
throw new Error(
|
||||
'Attempted to render a Client Component from renderToMarkup. ' +
|
||||
'Attempted to render a Client Component from renderToHTML. ' +
|
||||
'This is not supported since it will never hydrate. ' +
|
||||
'Only render Server Components with renderToMarkup.',
|
||||
'Only render Server Components with renderToHTML.',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -63,9 +63,9 @@ export function resolveClientReferenceMetadata<T>(
|
||||
clientReference: ClientReference<T>,
|
||||
): ClientReferenceMetadata {
|
||||
throw new Error(
|
||||
'Attempted to render a Client Component from renderToMarkup. ' +
|
||||
'Attempted to render a Client Component from renderToHTML. ' +
|
||||
'This is not supported since it will never hydrate. ' +
|
||||
'Only render Server Components with renderToMarkup.',
|
||||
'Only render Server Components with renderToHTML.',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ export function getServerReferenceId<T>(
|
||||
serverReference: ServerReference<T>,
|
||||
): ServerReferenceId {
|
||||
throw new Error(
|
||||
'Attempted to render a Server Action from renderToMarkup. ' +
|
||||
'Attempted to render a Server Action from renderToHTML. ' +
|
||||
'This is not supported since it varies by version of the app. ' +
|
||||
'Use a fixed URL for any forms instead.',
|
||||
);
|
||||
@@ -85,7 +85,7 @@ export function getServerReferenceBoundArguments<T>(
|
||||
serverReference: ServerReference<T>,
|
||||
): null | Array<ReactClientValue> {
|
||||
throw new Error(
|
||||
'Attempted to render a Server Action from renderToMarkup. ' +
|
||||
'Attempted to render a Server Action from renderToHTML. ' +
|
||||
'This is not supported since it varies by version of the app. ' +
|
||||
'Use a fixed URL for any forms instead.',
|
||||
);
|
||||
|
||||
@@ -517,13 +517,13 @@
|
||||
"529": "Expected stylesheet with precedence to not be updated to a different kind of <link>. Check the `rel`, `href`, and `precedence` props of this component. Alternatively, check whether two different <link> components render in the same slot or share the same key.%s",
|
||||
"530": "The render was aborted by the server with a promise.",
|
||||
"531": "react-markup is not supported outside a React Server Components environment.",
|
||||
"532": "Attempted to render a Client Component from renderToMarkup. This is not supported since it will never hydrate. Only render Server Components with renderToMarkup.",
|
||||
"533": "Attempted to render a Server Action from renderToMarkup. This is not supported since it varies by version of the app. Use a fixed URL for any forms instead.",
|
||||
"534": "renderToMarkup should not have emitted Client References. This is a bug in React.",
|
||||
"535": "renderToMarkup should not have emitted Server References. This is a bug in React.",
|
||||
"536": "Cannot pass ref in renderToMarkup because they will never be hydrated.",
|
||||
"537": "Cannot pass event handlers (%s) in renderToMarkup because the HTML will never be hydrated so they can never get called.",
|
||||
"538": "Cannot use state or effect Hooks in renderToMarkup because this component will never be hydrated.",
|
||||
"532": "Attempted to render a Client Component from renderToHTML. This is not supported since it will never hydrate. Only render Server Components with renderToHTML.",
|
||||
"533": "Attempted to render a Server Action from renderToHTML. This is not supported since it varies by version of the app. Use a fixed URL for any forms instead.",
|
||||
"534": "renderToHTML should not have emitted Client References. This is a bug in React.",
|
||||
"535": "renderToHTML should not have emitted Server References. This is a bug in React.",
|
||||
"536": "Cannot pass ref in renderToHTML because they will never be hydrated.",
|
||||
"537": "Cannot pass event handlers (%s) in renderToHTML because the HTML will never be hydrated so they can never get called.",
|
||||
"538": "Cannot use state or effect Hooks in renderToHTML because this component will never be hydrated.",
|
||||
"539": "Binary RSC chunks cannot be encoded as strings. This is a bug in the wiring of the React streams.",
|
||||
"540": "String chunks need to be passed in their original shape. Not split into smaller string chunks. This is a bug in the wiring of the React streams.",
|
||||
"541": "Compared context values must be arrays"
|
||||
|
||||
Reference in New Issue
Block a user