@@ -3,10 +3,6 @@ import { toJs, jsx } from 'estree-util-to-js';
3
3
4
4
import bundleCode from './bundle.mjs' ;
5
5
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
-
10
6
/**
11
7
* Executes server-side JavaScript code in a safe, isolated context.
12
8
* This function takes a string of JavaScript code, bundles it, and then runs it
@@ -26,12 +22,7 @@ export async function executeServerCode(serverCode, requireFn) {
26
22
// Create a new Function from the bundled server code.
27
23
// The `require` argument is passed into the function's scope, allowing the
28
24
// `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 ) ;
35
26
36
27
// Execute the dynamically created function with the provided `requireFn`.
37
28
// The result of this execution is the dehydrated content from the server-side rendering.
@@ -62,7 +53,7 @@ export async function processJSXEntry(
62
53
// `buildServerProgram` takes the JSX-derived code and prepares it for server execution.
63
54
// `executeServerCode` then runs this code in a Node.js environment to produce
64
55
// the initial HTML content (dehydrated state) that will be sent to the client.
65
- const serverCode = buildServerProgram ( code , SSRvariable ) ;
56
+ const serverCode = buildServerProgram ( code ) ;
66
57
const dehydrated = await executeServerCode ( serverCode , requireFn ) ;
67
58
68
59
// `buildClientProgram` prepares the JSX-derived code for client-side execution.
0 commit comments