Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hcaptcha/react-hcaptcha

Package Overview
Dependencies
Maintainers
4
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hcaptcha/react-hcaptcha - npm Package Compare versions

Comparing version 0.3.4 to 0.3.5

12

dist/index.js

@@ -38,8 +38,8 @@ "use strict";

var onLoadListeners = [];
var captchaScriptCreated = false; // Generate hCaptcha API Script
var apiScriptRequested = false; // Generate hCaptcha API Script
var CaptchaScript = function CaptchaScript() {
var mountCaptchaScript = function mountCaptchaScript() {
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
apiScriptRequested = true; // Create global onload callback
// Create global onload callback
window.hcaptchaOnLoad = function () {

@@ -84,3 +84,2 @@ // Iterate over onload listeners, call each listener

var isApiReady = typeof hcaptcha !== 'undefined';
if (!isApiReady) captchaScriptCreated = false;
_this.ref = React.createRef();

@@ -114,6 +113,5 @@ _this.state = {

//Check if hCaptcha has already been loaded, if not create script tag and wait to render captcha
if (!captchaScriptCreated) {
if (!apiScriptRequested) {
// Only create the script tag once, use a global variable to track
captchaScriptCreated = true;
CaptchaScript({
mountCaptchaScript({
apihost: apihost,

@@ -120,0 +118,0 @@ assethost: assethost,

{
"name": "@hcaptcha/react-hcaptcha",
"version": "0.3.4",
"version": "0.3.5",
"description": "A React library for hCaptcha",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -6,6 +6,7 @@ const React = require('react');

let onLoadListeners = [];
let captchaScriptCreated = false;
let apiScriptRequested = false;
// Generate hCaptcha API Script
const CaptchaScript = (params={}) => {
const mountCaptchaScript = (params={}) => {
apiScriptRequested = true;
// Create global onload callback

@@ -51,5 +52,2 @@ window.hcaptchaOnLoad = () => {

if (!isApiReady)
captchaScriptCreated = false;
this.ref = React.createRef();

@@ -71,6 +69,5 @@

if (!captchaScriptCreated) {
if (!apiScriptRequested) {
// Only create the script tag once, use a global variable to track
captchaScriptCreated = true;
CaptchaScript({
mountCaptchaScript({
apihost,

@@ -77,0 +74,0 @@ assethost,

import React from "react";
import ReactDOM from "react-dom";
import ReactTestUtils, { act } from "react-dom/test-utils";
import HCaptcha from "../src/index";
import {getMockedHcaptcha, MOCK_EKEY, MOCK_TOKEN, MOCK_WIDGET_ID} from "./hcaptcha.mock";
let HCaptcha;

@@ -20,2 +20,7 @@ const TEST_PROPS = {

beforeEach(() => {
jest.isolateModules(() => {
// Use node's `require` because `jest.isolateModules` cannot be async to use it with `await import()`
HCaptcha = require('../src/index');
});
mockFns = {

@@ -263,3 +268,16 @@ onChange: jest.fn(),

});
it("shouldn't create multiple scripts for multiple captchas", () => {
ReactTestUtils.renderIntoDocument(<HCaptcha
sitekey={TEST_PROPS.sitekey}
/>);
ReactTestUtils.renderIntoDocument(<HCaptcha
sitekey={TEST_PROPS.sitekey}
/>);
const scripts = document.querySelectorAll("head > script");
expect(scripts.length).toBe(1);
})
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc