Skip to content

Commit 5fe49a3

Browse files
authored
fix(web): Simple copy-paste components showing HTML instead of React (#1721)
1 parent b792358 commit 5fe49a3

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

apps/web/src/components/component-code-view.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ export const ComponentCodeView = ({
3434
const [isCopied, setIsCopied] = React.useState<boolean>(false);
3535

3636
let code = component.code.html;
37-
if (
38-
selectedLanguage === "react" &&
39-
selectedReactCodeVariant in component.code
40-
) {
41-
// Resets the regex so that it doesn't break in subsequent runs
42-
srcAttributeRegex.lastIndex = 0;
43-
code = component.code[selectedReactCodeVariant] ?? "";
37+
if (selectedLanguage === "react") {
38+
const codeForSelectedVariant = component.code[selectedReactCodeVariant];
39+
if (codeForSelectedVariant) {
40+
code = codeForSelectedVariant;
41+
} else if (component.code.react) {
42+
code = component.code.react;
43+
}
4444
}
45+
srcAttributeRegex.lastIndex = 0;
4546
code = code.replaceAll(
4647
srcAttributeRegex,
4748
(_match, uri) => `src="https://react.email${uri}"`,
@@ -92,7 +93,7 @@ export const ComponentCodeView = ({
9293
</Tabs.List>
9394
</Tabs.Root>
9495
<div className="flex gap-2">
95-
{selectedLanguage === "react" ? (
96+
{selectedLanguage === "react" && !component.code.react ? (
9697
<ReactVariantSelect
9798
onChange={(newValue) => {
9899
localStorage.setItem("code-variant", newValue);

0 commit comments

Comments
 (0)