From ed8a4bfc759e63ca21d3dd5199985e64a2f4e3a5 Mon Sep 17 00:00:00 2001 From: raphi Date: Fri, 23 Oct 2026 20:46:21 +0200 Subject: [PATCH 1/3] feat: support React 19 React 19 ignores `defaultProps` on function components, so on React 19 the geolocation button disappeared and the input lost its default placeholder. Defaults are now parameter defaults in the render function (`geolocation = true`, `options` as a module-level constant, `placeholder = 'Search places...'` passed explicitly to the input). - peerDependencies: react and react-dom widened to ^16 || ^17 || ^18 || ^19 - types: use `React.JSX.Element` (global `JSX` namespace is gone in @types/react 19) and widen @types/react to ^18.2.58 || ^19 so npm dedupes it with the app's version - build: rollup config uses `with { type: 'json' }` (Node 22 dropped import assertions, `assert` failed the build) - version 2.3.0 Co-Authored-By: Claude Opus 5.5 --- package-lock.json | 10 +++++----- package.json | 8 ++++---- rollup.config.js | 2 +- src/PlaceKit.jsx | 18 +++++++++--------- src/index.d.ts | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index 957b53d..e6e1201 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,16 @@ { "name": "@placekit/autocomplete-react", - "version": "2.2.2", + "version": "2.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@placekit/autocomplete-react", - "version": "2.2.2", + "version": "2.3.0", "license": "MIT", "dependencies": { "@placekit/autocomplete-js": "^2.2.1", - "@types/react": "^18.2.58", + "@types/react": "^18.2.58 || ^19", "prop-types": "^15.8.1" }, "devDependencies": { @@ -29,8 +29,8 @@ "rollup-plugin-copy": "^3.5.0" }, "peerDependencies": { - "react": "^16 || ^17 || ^18", - "react-dom": "^16 || ^17 || ^18" + "react": "^16 || ^17 || ^18 || ^19", + "react-dom": "^16 || ^17 || ^18 || ^19" } }, "node_modules/@aashutoshrathi/word-wrap": { diff --git a/package.json b/package.json index 2c9fa5c..7cdafb0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@placekit/autocomplete-react", - "version": "2.2.2", + "version": "2.3.0", "author": "PlaceKit ", "description": "PlaceKit Autocomplete React library", "keywords": [ @@ -63,11 +63,11 @@ }, "dependencies": { "@placekit/autocomplete-js": "^2.2.1", - "@types/react": "^18.2.58", + "@types/react": "^18.2.58 || ^19", "prop-types": "^15.8.1" }, "peerDependencies": { - "react": "^16 || ^17 || ^18", - "react-dom": "^16 || ^17 || ^18" + "react": "^16 || ^17 || ^18 || ^19", + "react-dom": "^16 || ^17 || ^18 || ^19" } } diff --git a/rollup.config.js b/rollup.config.js index 4c8d369..40690cb 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -4,7 +4,7 @@ import { babel } from '@rollup/plugin-babel'; import { nodeResolve } from '@rollup/plugin-node-resolve'; import copy from 'rollup-plugin-copy'; -import pkg from './package.json' assert { type: 'json' }; +import pkg from './package.json' with { type: 'json' }; const banner = [ `/*! ${pkg.name} v${pkg.version}`, '© placekit.io', diff --git a/src/PlaceKit.jsx b/src/PlaceKit.jsx index affe52e..d5b9778 100644 --- a/src/PlaceKit.jsx +++ b/src/PlaceKit.jsx @@ -3,13 +3,18 @@ import React, { forwardRef, useCallback, useEffect } from 'react'; import { usePlaceKit } from './usePlaceKit'; +// default props as parameter defaults (React 19 ignores `defaultProps` on function components) +// `options` default is a module-level constant to keep a stable reference across renders +const DEFAULT_OPTIONS = {}; + const PlaceKit = forwardRef( ( { apiKey, className, - geolocation, - options, + geolocation = true, + options = DEFAULT_OPTIONS, + placeholder = 'Search places...', onClient, onOpen, onClose, @@ -108,22 +113,17 @@ const PlaceKit = forwardRef( > Clear value - + ); }, ); -PlaceKit.defaultProps = { - geolocation: true, - options: {}, - placeholder: 'Search places...', -}; - PlaceKit.propTypes = { // component options geolocation: PropTypes.bool, className: PropTypes.string, + placeholder: PropTypes.string, // PlaceKit Autocomplete JS options apiKey: PropTypes.string.isRequired, diff --git a/src/index.d.ts b/src/index.d.ts index 218cd6e..ac39409 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -34,6 +34,6 @@ export type PlaceKitHooks = { state: PKAState; }; -declare function PlaceKit(props: PlaceKitProps): JSX.Element; +declare function PlaceKit(props: PlaceKitProps): React.JSX.Element; declare function usePlaceKit(apiKey: string, options?: PlaceKitOptions): PlaceKitHooks; From 761b5b741a7667efdaaccb242327e27659b5207c Mon Sep 17 00:00:00 2001 From: raphi Date: Fri, 23 Oct 2026 20:58:32 +0200 Subject: [PATCH 2/3] fix: type PlaceKit return as React.ReactElement for @types/react 16 to 19 Co-Authored-By: Claude Opus 5.5 --- src/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.d.ts b/src/index.d.ts index ac39409..142bfae 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -34,6 +34,6 @@ export type PlaceKitHooks = { state: PKAState; }; -declare function PlaceKit(props: PlaceKitProps): React.JSX.Element; +declare function PlaceKit(props: PlaceKitProps): React.ReactElement; declare function usePlaceKit(apiKey: string, options?: PlaceKitOptions): PlaceKitHooks; From 23ec50eed4ee453ee48cadb0e3f04f8e372ce351 Mon Sep 17 00:00:00 2001 From: raphi Date: Sat, 24 Oct 2026 12:09:30 +0200 Subject: [PATCH 3/3] fix: keep defaultProps and @types/react ^18 for drop-in upgrades Apps on React 16 to 18 that read or mutate PlaceKit.defaultProps keep working, and the @types/react range no longer pulls React 19 types into React 18 projects on fresh installs. Parameter defaults still cover React 19. Co-Authored-By: Claude Opus 5.5 --- package-lock.json | 2 +- package.json | 2 +- src/PlaceKit.jsx | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index e6e1201..93b63a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "@placekit/autocomplete-js": "^2.2.1", - "@types/react": "^18.2.58 || ^19", + "@types/react": "^18.2.58", "prop-types": "^15.8.1" }, "devDependencies": { diff --git a/package.json b/package.json index 7cdafb0..22bac2f 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ }, "dependencies": { "@placekit/autocomplete-js": "^2.2.1", - "@types/react": "^18.2.58 || ^19", + "@types/react": "^18.2.58", "prop-types": "^15.8.1" }, "peerDependencies": { diff --git a/src/PlaceKit.jsx b/src/PlaceKit.jsx index d5b9778..4be80b4 100644 --- a/src/PlaceKit.jsx +++ b/src/PlaceKit.jsx @@ -6,6 +6,7 @@ import { usePlaceKit } from './usePlaceKit'; // default props as parameter defaults (React 19 ignores `defaultProps` on function components) // `options` default is a module-level constant to keep a stable reference across renders const DEFAULT_OPTIONS = {}; +const DEFAULT_PLACEHOLDER = 'Search places...'; const PlaceKit = forwardRef( ( @@ -14,7 +15,7 @@ const PlaceKit = forwardRef( className, geolocation = true, options = DEFAULT_OPTIONS, - placeholder = 'Search places...', + placeholder = DEFAULT_PLACEHOLDER, onClient, onOpen, onClose, @@ -119,11 +120,17 @@ const PlaceKit = forwardRef( }, ); +// kept for backward compatibility on React 16 to 18 (apps reading or mutating `PlaceKit.defaultProps`) +PlaceKit.defaultProps = { + geolocation: true, + options: DEFAULT_OPTIONS, + placeholder: DEFAULT_PLACEHOLDER, +}; + PlaceKit.propTypes = { // component options geolocation: PropTypes.bool, className: PropTypes.string, - placeholder: PropTypes.string, // PlaceKit Autocomplete JS options apiKey: PropTypes.string.isRequired,