Skip to content

Commit 5b6e124

Browse files
more streamline with format event handler
1 parent fc787e6 commit 5b6e124

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

reflex/.templates/web/utils/state.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
initialState,
1717
onLoadInternalEvent,
1818
state_name,
19-
exception_state_name,
19+
handle_frontend_exception,
2020
main_state_name,
2121
update_vars_internal,
2222
} from "$/utils/context";
@@ -969,7 +969,7 @@ export const useEventLoop = (
969969

970970
window.onerror = function (msg, url, lineNo, columnNo, error) {
971971
addEvents([
972-
ReflexEvent(`${exception_state_name}.handle_frontend_exception`, {
972+
ReflexEvent(handle_frontend_exception, {
973973
info: error.name + ": " + error.message + "\n" + error.stack,
974974
component_stack: "",
975975
}),
@@ -981,7 +981,7 @@ export const useEventLoop = (
981981
//https://github.com/mknichel/javascript-errors?tab=readme-ov-file#promise-rejection-events
982982
window.onunhandledrejection = function (event) {
983983
addEvents([
984-
ReflexEvent(`${exception_state_name}.handle_frontend_exception`, {
984+
ReflexEvent(handle_frontend_exception, {
985985
info:
986986
event.reason?.name +
987987
": " +

reflex/compiler/templates.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ def context_template(
288288
update_vars_internal = format_event_handler(
289289
UpdateVarsInternalState.update_vars_internal
290290
)
291-
exception_state_full = FrontendEventExceptionState.get_full_name()
291+
handle_frontend_exception = format_event_handler(
292+
FrontendEventExceptionState.handle_frontend_exception
293+
)
292294

293295
initial_state = initial_state or {}
294296
state_contexts_str = "".join([
@@ -304,7 +306,7 @@ def context_template(
304306
305307
export const update_vars_internal = "{update_vars_internal}"
306308
307-
export const exception_state_name = "{exception_state_full}"
309+
export const handle_frontend_exception = "{handle_frontend_exception}"
308310
309311
// These events are triggered on initial load and each page navigation.
310312
export const onLoadInternalEvent = () => {{
@@ -343,7 +345,7 @@ def context_template(
343345
344346
export const update_vars_internal = undefined
345347
346-
export const exception_state_name = undefined
348+
export const handle_frontend_exception = undefined
347349
348350
export const onLoadInternalEvent = () => []
349351

0 commit comments

Comments
 (0)