Skip to content

Commit

Permalink
fix replacement not being forwarded to copied contents
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmfern committed Sep 23, 2024
1 parent 784fe73 commit d3e8539
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions apps/web/src/components/component-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ const CodeView = ({ component }: { component: ImportedComponent }) => {

let code = "";
if (selectedCodeVariant in component.code) {
code = component.code[selectedCodeVariant] ?? "";
// Resets the regex so that it doesn't break in subsequent runs
srcAttributeRegex.lastIndex = 0;
code = (component.code[selectedCodeVariant] ?? "").replaceAll(
srcAttributeRegex,
(_match, uri) => `src="https://react.email${uri}"`,
);
} else {
throw new Error("The code variant selected is not available", {
cause: {
Expand All @@ -205,9 +210,6 @@ const CodeView = ({ component }: { component: ImportedComponent }) => {
}
};

// Resets the regex so that it doesn't break in subsequent runs
srcAttributeRegex.lastIndex = 0;

return (
<div className="flex h-full w-full flex-col gap-2 bg-slate-3">
<div className="relative flex w-full justify-between gap-4 border-b border-solid border-slate-4 p-4 text-xs">
Expand Down Expand Up @@ -288,10 +290,7 @@ const CodeView = ({ component }: { component: ImportedComponent }) => {
</div>
<div className="h-full w-full overflow-auto">
<CodeBlock language={selectedCodeVariant === "html" ? "html" : "tsx"}>
{code.replaceAll(
srcAttributeRegex,
(_match, uri) => `src="https://react.email${uri}"`,
)}
{code}
</CodeBlock>
</div>
</div>
Expand Down

0 comments on commit d3e8539

Please sign in to comment.