Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow call_function callback argument to be added afterwards #4552

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

masenf
Copy link
Collaborator

@masenf masenf commented Dec 17, 2024

The default behavior for EventSpec is to treat the spec as a partial, wherein if additional unfilled arguments are available, and the event trigger wants to pass additional arguments, they will be applied positionally.

However, it never makes sense to fill in callback with an event trigger arg. Therefore, if the callback is not provided initially, set it to None explicitly so that some invalid value cannot be added later.

Makes code like this work

rx.input(on_blur=rx.console_log("Input blurred"))

Without this patch, the frontend raises exception:

[Reflex Frontend Exception]
 TypeError: event.payload.callback is not a function
    at applyEvent (webpack-internal:///./utils/state.js:246:35)
    at processEvent (webpack-internal:///./utils/state.js:344:27)
    at queueEvents (webpack-internal:///./utils/state.js:321:11)
    at addEvents (webpack-internal:///./utils/state.js:660:13)
    at eval (webpack-internal:///./pages/index.js:134:111)
    at HTMLUnknownElement.callCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:4164:14)
    at Object.invokeGuardedCallbackDev (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:4213:16)
    at invokeGuardedCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:4277:31)
    at invokeGuardedCallbackAndCatchFirstError (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:4291:25)
    at executeDispatch (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:9041:3)
    at processDispatchQueueItemsInOrder (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:9073:7)
    at processDispatchQueue (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:9086:5)
    at dispatchEventsForPlugins (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:9097:3)
    at eval (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:9288:12)
    at batchedUpdates$1 (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:26174:12)
    at batchedUpdates (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:3991:12)
    at dispatchEventForPluginEventSystem (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:9287:3)
    at dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay 
(webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:6465:5)
    at dispatchEvent (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:6457:5)
    at dispatchDiscreteEvent (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:6430:5)

The default behavior for EventSpec is to treat the spec as a partial, wherein
if additional unfilled arguments are available, and the event trigger wants to
pass additional arguments, they will be applied positionally.

However, it never makes sense to fill in `callback` with an event trigger arg.
Therefore, if the callback is not provided initially, set it to None explicitly
so that some invalid value cannot be added later.
@masenf masenf merged commit 316a0c9 into main Jan 3, 2025
41 checks passed
@masenf masenf deleted the masenf/safe-call_function-callback branch January 3, 2025 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants