@@ -3,10 +3,6 @@ import { toJs, jsx } from 'estree-util-to-js';
33
44import 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