Skip to content

Commit 2546d50

Browse files
authored
hotfix(rolldown): fix breaking change (#395)
* hotfix(rolldown): fix breaking change
1 parent a386315 commit 2546d50

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

src/generators/web/utils/generate.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ export default () => {
7676
* Builds a server-side rendering (SSR) program.
7777
*
7878
* @param {string} componentCode - Code expression representing a JSX component
79-
* @param {string} variable - The variable to output it to
8079
*/
81-
const buildServerProgram = (componentCode, variable) => {
80+
const buildServerProgram = componentCode => {
8281
return [
8382
// JSX component imports
8483
...baseImports,
@@ -88,7 +87,7 @@ export default () => {
8887

8988
// Render the component to an HTML string
9089
// The output can be embedded directly into the server's HTML template
91-
`const ${variable} = render(${componentCode});`,
90+
`return render(${componentCode});`,
9291
].join('\n');
9392
};
9493

src/generators/web/utils/processing.mjs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import { toJs, jsx } from 'estree-util-to-js';
33

44
import bundleCode from './bundle.mjs';
55

6-
// Generate a unique variable name to capture the result of the server-side code.
7-
// This prevents naming conflicts.
8-
const SSRvariable = `_${Math.random().toString(36).slice(2)}`;
9-
106
/**
117
* Executes server-side JavaScript code in a safe, isolated context.
128
* This function takes a string of JavaScript code, bundles it, and then runs it
@@ -26,12 +22,7 @@ export async function executeServerCode(serverCode, requireFn) {
2622
// Create a new Function from the bundled server code.
2723
// The `require` argument is passed into the function's scope, allowing the
2824
// `bundledServer` code to use it for dynamic imports.
29-
// The `return ${variable};` statement ensures that the value assigned to
30-
// the dynamic variable within the `bundledServer` code is returned by this function.
31-
const executedFunction = new Function(
32-
'require',
33-
`${bundledServer}\nreturn ${SSRvariable};`
34-
);
25+
const executedFunction = new Function('require', bundledServer);
3526

3627
// Execute the dynamically created function with the provided `requireFn`.
3728
// The result of this execution is the dehydrated content from the server-side rendering.
@@ -62,7 +53,7 @@ export async function processJSXEntry(
6253
// `buildServerProgram` takes the JSX-derived code and prepares it for server execution.
6354
// `executeServerCode` then runs this code in a Node.js environment to produce
6455
// the initial HTML content (dehydrated state) that will be sent to the client.
65-
const serverCode = buildServerProgram(code, SSRvariable);
56+
const serverCode = buildServerProgram(code);
6657
const dehydrated = await executeServerCode(serverCode, requireFn);
6758

6859
// `buildClientProgram` prepares the JSX-derived code for client-side execution.

0 commit comments

Comments
 (0)