Skip to content

Commit

Permalink
Rename renderToMarkup to renderToHTML
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Aug 14, 2024
1 parent 3e7b8e4 commit 3b6d41d
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
}

Expand All @@ -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.',
);
}

Expand All @@ -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.',
);
}

Expand All @@ -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.',
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react-markup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-markup/src/ReactFizzConfigMarkup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-markup/src/ReactMarkupClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type MarkupOptions = {
onError?: (error: mixed, errorInfo: ErrorInfo) => ?string,
};

export function renderToMarkup(
export function renderToHTML(
children: ReactNodeList,
options?: MarkupOptions,
): Promise<string> {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-markup/src/ReactMarkupServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
18 changes: 9 additions & 9 deletions packages/react-markup/src/__tests__/ReactMarkupClient-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>');
});

Expand All @@ -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>,
Expand All @@ -76,7 +76,7 @@ if (!__EXPERIMENTAL__) {
}

await expect(async () => {
await ReactMarkup.renderToMarkup(<Component />);
await ReactMarkup.renderToHTML(<Component />);
}).rejects.toThrow();
});

Expand All @@ -87,7 +87,7 @@ if (!__EXPERIMENTAL__) {
}

await expect(async () => {
await ReactMarkup.renderToMarkup(<Component />);
await ReactMarkup.renderToHTML(<Component />);
}).rejects.toThrow();
});

Expand All @@ -100,7 +100,7 @@ if (!__EXPERIMENTAL__) {
}

await expect(async () => {
await ReactMarkup.renderToMarkup(<Component />);
await ReactMarkup.renderToHTML(<Component />);
}).rejects.toThrow();
});

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -176,7 +176,7 @@ if (!__EXPERIMENTAL__) {
);
}

const html = await ReactMarkup.renderToMarkup(<Component />);
const html = await ReactMarkup.renderToHTML(<Component />);
expect(html).toBe('<div>01</div>');
});

Expand All @@ -199,7 +199,7 @@ if (!__EXPERIMENTAL__) {
}

await expect(async () => {
await ReactMarkup.renderToMarkup(
await ReactMarkup.renderToHTML(
<div>
<Foo />
</div>,
Expand Down
18 changes: 9 additions & 9 deletions packages/react-markup/src/__tests__/ReactMarkupServer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>');
Expand All @@ -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',
Expand All @@ -104,7 +104,7 @@ if (!__EXPERIMENTAL__) {
}

await expect(async () => {
await ReactMarkup.renderToMarkup(React.createElement(Component));
await ReactMarkup.renderToHTML(React.createElement(Component));
}).rejects.toThrow();
});

Expand All @@ -116,7 +116,7 @@ if (!__EXPERIMENTAL__) {
}

await expect(async () => {
await ReactMarkup.renderToMarkup(React.createElement(Component));
await ReactMarkup.renderToHTML(React.createElement(Component));
}).rejects.toThrow();
});

Expand All @@ -130,7 +130,7 @@ if (!__EXPERIMENTAL__) {
}

await expect(async () => {
await ReactMarkup.renderToMarkup(React.createElement(Component));
await ReactMarkup.renderToHTML(React.createElement(Component));
}).rejects.toThrow();
});

Expand Down Expand Up @@ -173,7 +173,7 @@ if (!__EXPERIMENTAL__) {
);
}

const html = await ReactMarkup.renderToMarkup(
const html = await ReactMarkup.renderToHTML(
React.createElement(Component),
);
const container = document.createElement('div');
Expand Down Expand Up @@ -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>');
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-server/src/ReactFizzHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,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.',
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
}

Expand All @@ -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.',
);
}

Expand All @@ -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.',
);
Expand All @@ -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.',
);
Expand Down
14 changes: 7 additions & 7 deletions scripts/error-codes/codes.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3b6d41d

Please sign in to comment.