Skip to content

feat(render): in-house formatter #2361

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

Draft
wants to merge 53 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2cd741e
remove dependencies that are not going to be used anymore
gabrielmfern May 15, 2025
1d8691c
bring parsing and prettying in-house
gabrielmfern May 15, 2025
c8ddd41
add tests for some individual functions and comment others
gabrielmfern May 15, 2025
41f6879
fix infinite loop when there are no white space characters in text to…
gabrielmfern May 16, 2025
1e842c0
fixed extra line break in between two closing tags
gabrielmfern May 16, 2025
3592816
add basic test
gabrielmfern May 16, 2025
5c9665c
add more granular tests for wrapText
gabrielmfern May 16, 2025
d26cd40
add extra line break on tag start to avoid hanging properties
gabrielmfern May 16, 2025
56e2b46
update lock
gabrielmfern May 16, 2025
ee43b59
add tests for stripe's html and for property line-breaking
gabrielmfern May 16, 2025
b78233d
update snap
gabrielmfern May 16, 2025
4c74003
add test for case where we had infinite loop
gabrielmfern May 16, 2025
f5ed891
fix text wrapping issues
gabrielmfern May 16, 2025
94005a5
dont count indentation as part of the length of the line
gabrielmfern May 16, 2025
2f25fe5
add the missing lineBreak option to the pretty call in the renders
gabrielmfern May 16, 2025
d2f5ca4
add test that ensures quality of codepen template's pretty printing
gabrielmfern May 16, 2025
fcd6352
separate comment and doctype for proper parsing
gabrielmfern May 16, 2025
fe68ab4
remove .only
gabrielmfern May 16, 2025
ca91744
add test snapshot for if mso test
gabrielmfern May 16, 2025
9917d07
update snaps
gabrielmfern May 19, 2025
fefd9df
separate parser from formatter
gabrielmfern Jul 11, 2025
0ba5c2a
make the options optional
gabrielmfern Jul 11, 2025
0b70377
update snapshots
gabrielmfern Jul 14, 2025
f695356
fix snapshot for style wrapping
gabrielmfern Jul 14, 2025
c4ff2fa
add initial verison of style multi-line formatting
gabrielmfern Jul 15, 2025
f85fe7e
update snapshots
gabrielmfern Jul 15, 2025
b7dfc42
use a negative lookbehind to not break at html entities
gabrielmfern Jul 15, 2025
71e1559
update snapshot
gabrielmfern Jul 15, 2025
85d05ad
add test for broken parsing
gabrielmfern Jul 15, 2025
919c3c1
fix infinte loops when missing portions of properties
gabrielmfern Jul 15, 2025
84e541a
update tests
gabrielmfern Jul 15, 2025
ae56a01
wip
gabrielmfern Jul 17, 2025
4db64aa
don't wrap text inside style or script tags
gabrielmfern Jul 17, 2025
40739dc
Revert "wip"
gabrielmfern Jul 17, 2025
f77574c
move the printing functions up
gabrielmfern Jul 17, 2025
f13ed85
remove only
gabrielmfern Jul 17, 2025
2e8370e
add space to the single line void tags
gabrielmfern Jul 17, 2025
179ccd1
update snapshots
gabrielmfern Jul 17, 2025
6294f0e
update obsolete snapshot
gabrielmfern Jul 17, 2025
f3e74cc
update snapshots
gabrielmfern Jul 18, 2025
fa30c73
Merge branch 'main' into fix/prettier-parsing-errors
gabrielmfern Jul 18, 2025
bda1f96
remove agents
gabrielmfern Jul 18, 2025
40318fa
Merge branch 'main' into fix/prettier-parsing-errors
gabrielmfern Jul 18, 2025
f4473b0
update snapshot for new tests
gabrielmfern Jul 18, 2025
f9fbb11
Merge branch 'main' into fix/prettier-parsing-errors
gabrielmfern Jul 18, 2025
0ccf93b
first effort at simplifying wrapText function
gabrielmfern Jul 22, 2025
92faf63
remove obsolete snap
gabrielmfern Jul 23, 2025
42141b0
remove line prefix from wrapText, fix issue with spaces being removed…
gabrielmfern Jul 23, 2025
f841d13
update with improved result on text wrapping
gabrielmfern Jul 23, 2025
99253e2
update snapshots
gabrielmfern Jul 23, 2025
7008a51
remove in-hosue parser in favor of node-html-parser
gabrielmfern Jul 23, 2025
bbb6d85
lint
gabrielmfern Jul 23, 2025
ad774ef
fix type issue
gabrielmfern Jul 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions packages/render/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@
},
"dependencies": {
"html-to-text": "^9.0.5",
"prettier": "^3.5.3",
"react-promise-suspense": "^0.3.4"
"node-html-parser": "^7.0.1"
},
"peerDependencies": {
"react": "^18.0 || ^19.0 || ^19.0.0-rc",
Expand All @@ -95,10 +94,10 @@
"devDependencies": {
"@edge-runtime/vm": "5.0.0",
"@types/html-to-text": "9.0.4",
"@types/prettier": "3.0.0",
"@types/react": "npm:[email protected]",
"@types/react-dom": "npm:[email protected]",
"jsdom": "26.1.0",
"react-promise-suspense": "^0.3.4",
"tsconfig": "workspace:*",
"tsup": "8.4.0",
"typescript": "5.8.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,53 +53,3 @@ exports[`render on the browser environment > should properly wait for Suepsense
`;

exports[`render on the browser environment > should throw error of rendering an invalid element instead of writing them into a template tag 1`] = `[Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.]`;

exports[`render on the browser environment > that it properly waits for Suepsense boundaries to resolve before resolving 1`] = `
"<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><!--$?--><template id="B:0"></template><!--/$--><div hidden id="S:0"><div><!doctype html>
<html>
<head>
<title>Example Domain</title>

<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;

}
div {
width: 600px;
margin: 5em auto;
padding: 2em;
background-color: #fdfdff;
border-radius: 0.5em;
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
div {
margin: 0 auto;
width: auto;
}
}
</style>
</head>

<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
domain in literature without prior coordination or asking for permission.</p>
<p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
</div></div><script>$RC=function(b,c,e){c=document.getElementById(c);c.parentNode.removeChild(c);var a=document.getElementById(b);if(a){b=a.previousSibling;if(e)b.data="$!",a.setAttribute("data-dgst",e);else{e=b.parentNode;a=b.nextSibling;var f=0;do{if(a&&8===a.nodeType){var d=a.data;if("/$"===d)if(0===f)break;else f--;else"$"!==d&&"$?"!==d&&"$!"!==d||f++}d=a.nextSibling;e.removeChild(a);a=d}while(a);for(;c.firstChild;)e.insertBefore(c.firstChild,a);b.data="$"}b._reactRetry&&b._reactRetry()}};$RC("B:0","S:0")</script>"
`;
4 changes: 3 additions & 1 deletion packages/render/src/browser/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export const render = async (node: React.ReactNode, options?: Options) => {
const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, '')}`;

if (options?.pretty) {
return pretty(document);
return pretty(document, {
lineBreak: '\n',
});
}

return document;
Expand Down
4 changes: 3 additions & 1 deletion packages/render/src/node/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export const render = async (node: React.ReactNode, options?: Options) => {
const document = `${doctype}${html.replace(/<!DOCTYPE.*?>/, '')}`;

if (options?.pretty) {
return pretty(document);
return pretty(document, {
lineBreak: '\n',
});
}

return document;
Expand Down
Loading
Loading