Repository navigation
fix: isolate dynamic JavaScript execution environments - #7870
Conversation
[Medium impact] The PR appears safe to merge; the latest change fixes the release note without changing runtime behavior. SummaryThe PR gives server-provided JavaScript an explicit set of available names, allowing smaller frontend bundles while preserving script results and event callbacks.
somiljain2006 accepted the inline dependency-name duplication because it matches the surrounding style and is small. No new issues found. Reviews (9) · Last reviewed commit: "Describe the actual script scope in the ..." · Reviewed by Greptile |
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
Merging this PR will regress 2 benchmarks1 warning
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
Generated callbacks call any helper compiled pages import from state.js, not only ReflexEvent: a Var operation inside a callback compiles to pyMod, isTrue, pyStrLength and so on. With a fixed six-name list those throw ReferenceError and the result never reaches the backend. The module imports itself and scriptScope() spreads its exports in front of the per-call addEvents, socket and token, so both evaluators share one parameter list built from the real export set. The typeof guards in createExecutionContext go away with it. The node-snippet tests stub stateExports, both vm harnesses link the self-import, and the README describes the script scope.
There was a problem hiding this comment.
All reported issues were addressed across 6 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
View guided diff | Re-trigger cubic
One Function-constructor evaluator covers callbacks, _call_script and _call_function: its body is a strict eval of the code parameter, so expressions and statement lists both keep their completion value, and no expression-first attempt is needed. It is compiled on the first script and takes every export of state.js plus addEvents, socket, navigate, params and token. The vitest file pins the contract in eight cases: completion value, every export visible, the four locals, strict mode and isolation, lazy compile, remount, string _call_function. The node-snippet template tests go; the call-site test checks the runScript sites declare the addEvents alias. The news fragment states the user-visible effect: a smaller shared chunk.
There was a problem hiding this comment.
All reported issues were addressed across 9 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
|
I pushed three commits on top of your branch. Here is what each one changes and why. Your version (up to 6759608). It replaced the direct
The approach fixes #7860. The direct c868dde: pass every
0c2cc28: replace the two evaluators with one
425e405: correct the news fragment. The fragment said scripts see "only I also updated the PR description to match the current code. |
The state.js harnesses link two special cases now: main's self-import of $/utils/state for server-provided scripts (#7870), and the real event_results.js module. Claude-Session: https://claude.ai/code/session_01LwJUCSPGJ9cvdFM2KLFHoH
All Submissions:
Type of change
Please delete options that are not relevant.
New Feature Submission:
Changes To Core Features:
closes #7860
Server-provided JavaScript (
rx.call_scriptcode,rx.call_functionfunctions and their result callbacks) no longer runs through a directevalinutils/state.js. A directevalstops the minifier from mangling the chunk that holds it; withfrontend_lazy_bundled_librarieson, this shrinks the shared chunk by about 88 KB (11 KB gzipped).runScripthelper compiles a Function-constructor evaluator on first use, so a CSP withoutunsafe-evalstill loads apps that never send scripts. Its body passes the code toeval, which sees only the Function's parameters and the globals, and runs it as a strict script, so statement lists keep their completion value.utils/state.js(ReflexEvent,refs,queueEvents,pyMod, ...), the late-boundaddEvents, thesocket,navigateandparamsof the event, the sessiontoken, and the globals. Names the module does not export (its imports, such aseventLoop) are no longer in scope.evalReactComponentuses a nativeimport()of the data URI instead ofeval("import(...)").packages/reflex-frontend/tests/run_script.test.jspins completion values, strict mode, scope, late-boundaddEventsacross event-loop remounts, and lazy compilation.test_state_js_template.pychecks that everyrunScriptcall site declares theaddEventsalias first.