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

onWidgetLoad is not called after a reload #77

Closed
EnzeGH opened this issue Jul 12, 2024 · 1 comment · Fixed by #78
Closed

onWidgetLoad is not called after a reload #77

EnzeGH opened this issue Jul 12, 2024 · 1 comment · Fixed by #78
Assignees

Comments

@EnzeGH
Copy link

EnzeGH commented Jul 12, 2024

Hello there,

The documentation for the onWidgetLoad() prop states the following:
"Callback invoked when the widget is loaded or reloaded (e.g., after a reset)."

However, when you run ref.current?.reset(), it is not being called again. Here's a small demo:

import { Turnstile } from "@marsidev/react-turnstile";
import { useRef } from "react";

export default function App() {
  const ref = useRef(null);

  return (
    <>
      <Turnstile
        ref={ref}
        siteKey="1x00000000000000000000AA"
        onWidgetLoad={() => console.log("Loaded!")}
      />

      {/* @ts-ignore */}
      <button onClick={() => ref.current?.reset()}>Reset widget</button>
    </>
  );
}
@marsidev marsidev self-assigned this Jul 13, 2024
@marsidev
Copy link
Owner

Hey @EnzeGH, thanks for bringing up this issue!

Currently, the onWidgetLoad callback is called after a successful execution of the internal window.turnstile?.render() method, as it returns the ID of the widget if the rendering was successful.

If you remove a widget and then explicitly render it, you will see the callback run again.

Maybe we should rename it to onWidgetRendered?

On the other hand, the window.turnstile?.reset() method does not return anything, so we can't know if the resetting has been successful or not. At this moment, I haven't found a way to run a callback after a successful reset (PRs welcome!)

Alternatively, you can use the onSuccess callback, which is a native callback and is executed when a widget is solved.

marsidev added a commit that referenced this issue Jul 14, 2024
@marsidev marsidev mentioned this issue Jul 14, 2024
@marsidev marsidev linked a pull request Jul 14, 2024 that will close this issue
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 a pull request may close this issue.

2 participants