-
Notifications
You must be signed in to change notification settings - Fork 47.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new package with renderToMarkup export #30105
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3d4fec9
Add react-html package skeleton
sebmarkbage a7df40b
Implement renderMarkup as a Fizz renderer
sebmarkbage 4def38f
Add bundle
sebmarkbage 23a7c2d
Tests
sebmarkbage 5a7d35a
Configure Flight rendering
sebmarkbage 2829604
Update packages/react-html/package.json
sebmarkbage 7817ea5
Update README
sebmarkbage 471c13b
Remove isPrimaryRenderer
sebmarkbage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# `react-html` | ||
|
||
This package provides the ability to render standalone HTML from Server Components for use in embedded contexts such as e-mails and RSS/Atom feeds. It cannot use Client Components and does not hydrate. It is intended to be paired with the generic React package, which is shipped as `react` to npm. | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install react react-html | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
import { renderToMarkup } from 'react-html'; | ||
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} />); | ||
// ... send e-mail using some e-mail provider | ||
await sendEmail({ to: email, contentType: 'text/html', body: htmlString }); | ||
} | ||
``` | ||
|
||
Note that this is an async function that needs to be awaited - unlike the legacy `renderToString` in `react-dom`. | ||
|
||
## API | ||
|
||
### `react-html` | ||
|
||
See https://react.dev/reference/react-html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
throw new Error( | ||
'react-html is not supported outside a React Server Components environment.', | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
throw new Error( | ||
'react-html is not supported outside a React Server Components environment.' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/react-html.react-server.production.js'); | ||
} else { | ||
module.exports = require('./cjs/react-html.react-server.development.js'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,38 @@ | ||||||
{ | ||||||
"name": "react-html", | ||||||
"version": "19.0.0", | ||||||
"private": true, | ||||||
"description": "React package generating embedded HTML markup such as e-mails using Server Components.", | ||||||
"main": "index.js", | ||||||
"repository": { | ||||||
"type": "git", | ||||||
"url": "https://github.com/facebook/react.git", | ||||||
"directory": "packages/react-html" | ||||||
}, | ||||||
"keywords": [ | ||||||
"react" | ||||||
], | ||||||
"license": "MIT", | ||||||
"bugs": { | ||||||
"url": "https://github.com/facebook/react/issues" | ||||||
}, | ||||||
"homepage": "https://react.dev/", | ||||||
"peerDependencies": { | ||||||
"react": "^19.0.0" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we start off here with the correct approach since renderer and React need to be in lock step?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's change all packages at once if we do that. |
||||||
}, | ||||||
"files": [ | ||||||
"LICENSE", | ||||||
"README.md", | ||||||
"index.js", | ||||||
"react-html.react-server.js", | ||||||
"cjs/" | ||||||
], | ||||||
"exports": { | ||||||
".": { | ||||||
"react-server": "./react-html.react-server.js", | ||||||
"default": "./index.js" | ||||||
}, | ||||||
"./src/*": "./src/*", | ||||||
"./package.json": "./package.json" | ||||||
} | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
export * from './src/ReactHTMLServer'; |
32 changes: 32 additions & 0 deletions
32
packages/react-html/src/ReactHTMLLegacyClientStreamConfig.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
// TODO: The legacy one should not use binary. | ||
|
||
export type StringDecoder = TextDecoder; | ||
|
||
export function createStringDecoder(): StringDecoder { | ||
return new TextDecoder(); | ||
} | ||
|
||
const decoderOptions = {stream: true}; | ||
|
||
export function readPartialStringChunk( | ||
decoder: StringDecoder, | ||
buffer: Uint8Array, | ||
): string { | ||
return decoder.decode(buffer, decoderOptions); | ||
} | ||
|
||
export function readFinalStringChunk( | ||
decoder: StringDecoder, | ||
buffer: Uint8Array, | ||
): string { | ||
return decoder.decode(buffer); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that there's no flag here but the whole package is private so doesn't get publish once we land. We can land and iterate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was worried this blocks it from being published in react-builds but it works: https://react-builds.vercel.app/api/prs/30105/packages/react-html