Skip to content

Commit fce8748

Browse files
authored
fix: Fix NextJS cacheComponents issue (#367)
1 parent 0da667c commit fce8748

3 files changed

Lines changed: 4260 additions & 3665 deletions

File tree

lib/src/component/HCaptcha.jsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,18 @@ export class HCaptcha extends React.Component {
8989
return;
9090
}
9191

92-
// Reset any stored variables / timers when unmounting
93-
hcaptcha.reset(captchaId);
94-
hcaptcha.remove(captchaId);
92+
try {
93+
// Reset any stored variables / timers when unmounting
94+
hcaptcha.reset(captchaId);
95+
hcaptcha.remove(captchaId);
96+
} catch (error) {
97+
// Silently handle errors (e.g., invalid captcha ID in React Strict Mode)
98+
// This can happen when React double-invokes effects in development
99+
} finally {
100+
// Always clear state to prevent issues in React Strict Mode
101+
this.captchaId = '';
102+
this._onReady = null;
103+
}
95104
}
96105

97106
shouldComponentUpdate(nextProps, nextState) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@hcaptcha/react-hcaptcha",
33
"description": "A React library for hCaptcha",
4-
"version": "2.0.1",
4+
"version": "2.0.2",
55
"author": "hCaptcha team and contributors",
66
"license": "MIT",
77
"repository": {

0 commit comments

Comments
 (0)