Skip to content

Commit

Permalink
fix: inputComponents now get stable callbacks (#819)
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus authored May 13, 2024
1 parent 2c00ac1 commit 8b0919c
Show file tree
Hide file tree
Showing 24 changed files with 65 additions and 52 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [0.41.1] - 2024-05-13

### Fixes

- Custom `inputComponents` (in sign in/up form fields) now get reference-stable callbacks.

## [0.41.0] - 2024-05-09

### Breaking changes
Expand Down
32 changes: 21 additions & 11 deletions examples/for-tests/src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import "./App.css";

import AppWithoutRouter from "./AppWithoutRouter";
Expand Down Expand Up @@ -289,21 +289,31 @@ const incorrectFormFields = [
},
];

const DropdownInputComponent = ({ value, name, onChange }) => {
const onChangeRef = useRef(onChange);

if (onChangeRef.current !== onChange) {
throw new Error("callbacks passed to inputComponents should be reference stable");
}

return (
<select value={value} name={name} onChange={(e) => onChange(e.target.value)}>
<option value="" disabled hidden>
Select an option
</option>
<option value="option 1">Option 1</option>
<option value="option 2">Option 2</option>
<option value="option 3">Option 3</option>
</select>
);
};

const customFields = [
{
id: "select-dropdown",
label: "Select Dropdown",
nonOptionalErrorMsg: "Select dropdown is not an optional",
inputComponent: ({ value, name, onChange }) => (
<select value={value} name={name} onChange={(e) => onChange(e.target.value)}>
<option value="" disabled hidden>
Select an option
</option>
<option value="option 1">Option 1</option>
<option value="option 2">Option 2</option>
<option value="option 3">Option 3</option>
</select>
),
inputComponent: DropdownInputComponent,
optional: true,
},
{
Expand Down
3 changes: 2 additions & 1 deletion lib/build/components/assets/blockedIcon.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/build/components/assets/otpEmailIcon.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/build/components/assets/otpSMSIcon.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/build/components/assets/totpIcon.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/build/emailpassword-shared9.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/genericComponentOverrideContext.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/build/recipe/passwordless/recipe.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/recipe/thirdparty/prebuiltui.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/recipe/thirdpartyemailpassword/prebuiltui.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/build/recipe/totp/recipe.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/ts/recipe/emailpassword/components/library/formBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function InputComponentWrapper(props: {
value,
});
},
[onInputFocus, field]
[onInputFocus, field.id]
);

const useCallbackOnInputBlur = useCallback<(value: string) => void>(
Expand All @@ -76,7 +76,7 @@ function InputComponentWrapper(props: {
value,
});
},
[onInputBlur, field]
[onInputBlur, field.id]
);

const useCallbackOnInputChange = useCallback(
Expand All @@ -86,7 +86,7 @@ function InputComponentWrapper(props: {
value,
});
},
[onInputChange, field]
[onInputChange, field.id]
);

return field.inputComponent !== undefined ? (
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
export const package_version = "0.41.0";
export const package_version = "0.41.1";
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supertokens-auth-react",
"version": "0.41.0",
"version": "0.41.1",
"description": "ReactJS SDK that provides login functionality with SuperTokens.",
"main": "./index.js",
"engines": {
Expand Down

0 comments on commit 8b0919c

Please sign in to comment.