From b80bbfcb821c561fde8a538abf226fddaf777179 Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 13:04:26 -0700 Subject: [PATCH 01/16] SSR patch: react-aria/utils/useId seeds id with current package version instead of random number to preserve client/server match --- babel.config.json | 3 +- lib/babel-plugin-package-json-version.js | 38 ++++++++++++++++++++++++ packages/@react-aria/utils/src/useId.ts | 7 +++-- 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 lib/babel-plugin-package-json-version.js diff --git a/babel.config.json b/babel.config.json index c73d561f2f9..3b32117185a 100644 --- a/babel.config.json +++ b/babel.config.json @@ -63,7 +63,8 @@ "@babel/plugin-proposal-export-namespace-from", "@babel/plugin-syntax-class-properties", "transform-glob-import", - "babel-plugin-macros" + "babel-plugin-macros", + "./lib/babel-plugin-package-json-version" ], "sourceType": "unambiguous" } diff --git a/lib/babel-plugin-package-json-version.js b/lib/babel-plugin-package-json-version.js new file mode 100644 index 00000000000..f71dd6de033 --- /dev/null +++ b/lib/babel-plugin-package-json-version.js @@ -0,0 +1,38 @@ +const { resolve, sep, dirname } = require('path'); +const { existsSync } = require('fs'); + +const PACKAGE_JSON = 'package.json'; + +// returns path to closest package.json file while traversing up from given filepath +// this is compatible with a yarn/lerna workspaces environment +const resolvePackageJsonPath = (filepath) => { + let packageJsonPath = resolve(dirname(filepath), PACKAGE_JSON); + // while the parent directory does not have package.json and not at root of path + while (!existsSync(packageJsonPath)) { + const prevPackageJsonPath = packageJsonPath; + // step up into parent directory + packageJsonPath = resolve(dirname(dirname(packageJsonPath)), PACKAGE_JSON); + // ensure not already at root + if (packageJsonPath === prevPackageJsonPath) { + throw new Error(`could not resolve ${PACKAGE_JSON} from ${filepath}`); + } + } + // found a package.json file + return packageJsonPath; +} + +module.exports = function versionTransform() { + return { + visitor: { + Identifier(path, { filename }) { + if (path.node.name === '__PACKAGE_JSON_VERSION__') { + // find nearest package.json file + const packagePath = resolvePackageJsonPath(filename); + // replace reference with version string + const { version } = require(packagePath); + path.replaceWithSourceString('"' + version + '"'); + } + }, + }, + }; +}; diff --git a/packages/@react-aria/utils/src/useId.ts b/packages/@react-aria/utils/src/useId.ts index 57f2a6a247e..43ee2e12213 100644 --- a/packages/@react-aria/utils/src/useId.ts +++ b/packages/@react-aria/utils/src/useId.ts @@ -15,9 +15,10 @@ import {useLayoutEffect, useMemo, useState} from 'react'; let map: Map void> = new Map(); let id = 0; -// don't want to conflict with ids from v2, this will guarantee something unique +// don't want to conflict with ids from other instances of this module, this will *mostly* guarantee something unique // plus we'll know how many instances of this module are loaded on a page if there are more than one number ;) -let randomInstanceNumber = Math.round(Math.random() * 10000000000); +// NOTE: __PACKAGE_JSON_VERSION__ is injected by /lib/babel-plugin-package-json-version.js during babel transpilation +let packageVersion = __PACKAGE_JSON_VERSION__; /** * If a default is not provided, generate an id. @@ -25,7 +26,7 @@ let randomInstanceNumber = Math.round(Math.random() * 10000000000); */ export function useId(defaultId?: string): string { let [value, setValue] = useState(defaultId); - let res = useMemo(() => value || `react-aria-${randomInstanceNumber}-${++id}`, [value]); + let res = useMemo(() => value || `react-aria-utils-${packageVersion}-${++id}`, [value]); map.set(res, setValue); return res; } From be92d9596d1a3bfa7e73ccbfc516c67b720af045 Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 13:37:49 -0700 Subject: [PATCH 02/16] @react-aria/utils@3.1.1 --- packages/@react-aria/utils/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@react-aria/utils/package.json b/packages/@react-aria/utils/package.json index 68f2abda5a0..bdb18b26ae7 100644 --- a/packages/@react-aria/utils/package.json +++ b/packages/@react-aria/utils/package.json @@ -1,6 +1,6 @@ { "name": "@react-aria/utils", - "version": "3.1.0", + "version": "3.1.1", "description": "Spectrum UI components in React", "license": "Apache-2.0", "main": "dist/main.js", From 81d13c8a7ebd044ce0aab28009c39ba7dcd1b991 Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 14:57:19 -0700 Subject: [PATCH 03/16] Revert "@react-aria/utils@3.1.1" This reverts commit be92d9596d1a3bfa7e73ccbfc516c67b720af045. --- packages/@react-aria/utils/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@react-aria/utils/package.json b/packages/@react-aria/utils/package.json index bdb18b26ae7..68f2abda5a0 100644 --- a/packages/@react-aria/utils/package.json +++ b/packages/@react-aria/utils/package.json @@ -1,6 +1,6 @@ { "name": "@react-aria/utils", - "version": "3.1.1", + "version": "3.1.0", "description": "Spectrum UI components in React", "license": "Apache-2.0", "main": "dist/main.js", From b8547947b313865b8cac9eb4e39d822c0a1ff8bb Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 15:26:00 -0700 Subject: [PATCH 04/16] add root dev dependency on read-pkg-up --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index fc49705e9bb..0303720b4c5 100644 --- a/package.json +++ b/package.json @@ -140,6 +140,7 @@ "react-dom": "^0.14 || ^15 || ^16", "react-overlays": "0.8.3", "react-test-renderer": "^16.9.0", + "read-pkg-up": "^7.0.1", "recursive-readdir": "^2.2.2", "regenerator-runtime": "0.13.3", "rimraf": "^2.6.3", From 8c94f77a2773a4178b80141607113d6e73f4a60e Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 15:26:24 -0700 Subject: [PATCH 05/16] use read-pkg-up dependency in babel plugin --- lib/babel-plugin-package-json-version.js | 33 ++++++------------------ 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/lib/babel-plugin-package-json-version.js b/lib/babel-plugin-package-json-version.js index f71dd6de033..fed395ead92 100644 --- a/lib/babel-plugin-package-json-version.js +++ b/lib/babel-plugin-package-json-version.js @@ -1,35 +1,18 @@ -const { resolve, sep, dirname } = require('path'); -const { existsSync } = require('fs'); - -const PACKAGE_JSON = 'package.json'; - -// returns path to closest package.json file while traversing up from given filepath -// this is compatible with a yarn/lerna workspaces environment -const resolvePackageJsonPath = (filepath) => { - let packageJsonPath = resolve(dirname(filepath), PACKAGE_JSON); - // while the parent directory does not have package.json and not at root of path - while (!existsSync(packageJsonPath)) { - const prevPackageJsonPath = packageJsonPath; - // step up into parent directory - packageJsonPath = resolve(dirname(dirname(packageJsonPath)), PACKAGE_JSON); - // ensure not already at root - if (packageJsonPath === prevPackageJsonPath) { - throw new Error(`could not resolve ${PACKAGE_JSON} from ${filepath}`); - } - } - // found a package.json file - return packageJsonPath; -} +const { dirname } = require('path'); +const readPkgUp = require('read-pkg-up'); module.exports = function versionTransform() { return { visitor: { Identifier(path, { filename }) { if (path.node.name === '__PACKAGE_JSON_VERSION__') { - // find nearest package.json file - const packagePath = resolvePackageJsonPath(filename); + // find and read nearest package.json file + const resolvedPackage = readPkgUp.sync({ cwd: dirname(filename) }); + if (!resolvedPackage) { + throw new Error(`could not resolve package.json from ${filepath}`); + } // replace reference with version string - const { version } = require(packagePath); + const { version } = resolvedPackage.packageJson; path.replaceWithSourceString('"' + version + '"'); } }, From a92d1bd9616d915ee187f323fcc237de25d6c280 Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 15:47:30 -0700 Subject: [PATCH 06/16] useEffect in useId instead of useMemo --- packages/@react-aria/utils/src/useId.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/@react-aria/utils/src/useId.ts b/packages/@react-aria/utils/src/useId.ts index 43ee2e12213..5d3c9aa4daf 100644 --- a/packages/@react-aria/utils/src/useId.ts +++ b/packages/@react-aria/utils/src/useId.ts @@ -10,15 +10,14 @@ * governing permissions and limitations under the License. */ -import {useLayoutEffect, useMemo, useState} from 'react'; +import {useEffect, useLayoutEffect, useMemo, useState} from 'react'; let map: Map void> = new Map(); let id = 0; -// don't want to conflict with ids from other instances of this module, this will *mostly* guarantee something unique +// don't want to conflict with ids from v2, this will guarantee something unique // plus we'll know how many instances of this module are loaded on a page if there are more than one number ;) -// NOTE: __PACKAGE_JSON_VERSION__ is injected by /lib/babel-plugin-package-json-version.js during babel transpilation -let packageVersion = __PACKAGE_JSON_VERSION__; +let randomInstanceNumber = Math.round(Math.random() * 10000000000); /** * If a default is not provided, generate an id. @@ -26,9 +25,14 @@ let packageVersion = __PACKAGE_JSON_VERSION__; */ export function useId(defaultId?: string): string { let [value, setValue] = useState(defaultId); - let res = useMemo(() => value || `react-aria-utils-${packageVersion}-${++id}`, [value]); - map.set(res, setValue); - return res; + // preserve SSR rendering compatibility + // only use the auto-generated id after component mounts client-side + useEffect(() => { + const res = value || `react-aria-${randomInstanceNumber}-${++id}`; + map.set(res, setValue); + setValue(res); + }, [value]) + return value; } /** From 9d9830fb6f692f33a0612270c753ec3518a39237 Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 15:47:41 -0700 Subject: [PATCH 07/16] Revert "use read-pkg-up dependency in babel plugin" This reverts commit 8c94f77a2773a4178b80141607113d6e73f4a60e. --- lib/babel-plugin-package-json-version.js | 33 ++++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/babel-plugin-package-json-version.js b/lib/babel-plugin-package-json-version.js index fed395ead92..f71dd6de033 100644 --- a/lib/babel-plugin-package-json-version.js +++ b/lib/babel-plugin-package-json-version.js @@ -1,18 +1,35 @@ -const { dirname } = require('path'); -const readPkgUp = require('read-pkg-up'); +const { resolve, sep, dirname } = require('path'); +const { existsSync } = require('fs'); + +const PACKAGE_JSON = 'package.json'; + +// returns path to closest package.json file while traversing up from given filepath +// this is compatible with a yarn/lerna workspaces environment +const resolvePackageJsonPath = (filepath) => { + let packageJsonPath = resolve(dirname(filepath), PACKAGE_JSON); + // while the parent directory does not have package.json and not at root of path + while (!existsSync(packageJsonPath)) { + const prevPackageJsonPath = packageJsonPath; + // step up into parent directory + packageJsonPath = resolve(dirname(dirname(packageJsonPath)), PACKAGE_JSON); + // ensure not already at root + if (packageJsonPath === prevPackageJsonPath) { + throw new Error(`could not resolve ${PACKAGE_JSON} from ${filepath}`); + } + } + // found a package.json file + return packageJsonPath; +} module.exports = function versionTransform() { return { visitor: { Identifier(path, { filename }) { if (path.node.name === '__PACKAGE_JSON_VERSION__') { - // find and read nearest package.json file - const resolvedPackage = readPkgUp.sync({ cwd: dirname(filename) }); - if (!resolvedPackage) { - throw new Error(`could not resolve package.json from ${filepath}`); - } + // find nearest package.json file + const packagePath = resolvePackageJsonPath(filename); // replace reference with version string - const { version } = resolvedPackage.packageJson; + const { version } = require(packagePath); path.replaceWithSourceString('"' + version + '"'); } }, From 0135a00cb4279eec5b252984e15ce16ab24d9904 Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 15:48:34 -0700 Subject: [PATCH 08/16] remove local babel-plugin-package-json-version --- babel.config.json | 3 +- lib/babel-plugin-package-json-version.js | 38 ------------------------ 2 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 lib/babel-plugin-package-json-version.js diff --git a/babel.config.json b/babel.config.json index 3b32117185a..c73d561f2f9 100644 --- a/babel.config.json +++ b/babel.config.json @@ -63,8 +63,7 @@ "@babel/plugin-proposal-export-namespace-from", "@babel/plugin-syntax-class-properties", "transform-glob-import", - "babel-plugin-macros", - "./lib/babel-plugin-package-json-version" + "babel-plugin-macros" ], "sourceType": "unambiguous" } diff --git a/lib/babel-plugin-package-json-version.js b/lib/babel-plugin-package-json-version.js deleted file mode 100644 index f71dd6de033..00000000000 --- a/lib/babel-plugin-package-json-version.js +++ /dev/null @@ -1,38 +0,0 @@ -const { resolve, sep, dirname } = require('path'); -const { existsSync } = require('fs'); - -const PACKAGE_JSON = 'package.json'; - -// returns path to closest package.json file while traversing up from given filepath -// this is compatible with a yarn/lerna workspaces environment -const resolvePackageJsonPath = (filepath) => { - let packageJsonPath = resolve(dirname(filepath), PACKAGE_JSON); - // while the parent directory does not have package.json and not at root of path - while (!existsSync(packageJsonPath)) { - const prevPackageJsonPath = packageJsonPath; - // step up into parent directory - packageJsonPath = resolve(dirname(dirname(packageJsonPath)), PACKAGE_JSON); - // ensure not already at root - if (packageJsonPath === prevPackageJsonPath) { - throw new Error(`could not resolve ${PACKAGE_JSON} from ${filepath}`); - } - } - // found a package.json file - return packageJsonPath; -} - -module.exports = function versionTransform() { - return { - visitor: { - Identifier(path, { filename }) { - if (path.node.name === '__PACKAGE_JSON_VERSION__') { - // find nearest package.json file - const packagePath = resolvePackageJsonPath(filename); - // replace reference with version string - const { version } = require(packagePath); - path.replaceWithSourceString('"' + version + '"'); - } - }, - }, - }; -}; From 690f40337ae3ded8fca36b7332a34851bef092a7 Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 15:54:16 -0700 Subject: [PATCH 09/16] Revert "remove local babel-plugin-package-json-version" This reverts commit 0135a00cb4279eec5b252984e15ce16ab24d9904. --- babel.config.json | 3 +- lib/babel-plugin-package-json-version.js | 38 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 lib/babel-plugin-package-json-version.js diff --git a/babel.config.json b/babel.config.json index c73d561f2f9..3b32117185a 100644 --- a/babel.config.json +++ b/babel.config.json @@ -63,7 +63,8 @@ "@babel/plugin-proposal-export-namespace-from", "@babel/plugin-syntax-class-properties", "transform-glob-import", - "babel-plugin-macros" + "babel-plugin-macros", + "./lib/babel-plugin-package-json-version" ], "sourceType": "unambiguous" } diff --git a/lib/babel-plugin-package-json-version.js b/lib/babel-plugin-package-json-version.js new file mode 100644 index 00000000000..f71dd6de033 --- /dev/null +++ b/lib/babel-plugin-package-json-version.js @@ -0,0 +1,38 @@ +const { resolve, sep, dirname } = require('path'); +const { existsSync } = require('fs'); + +const PACKAGE_JSON = 'package.json'; + +// returns path to closest package.json file while traversing up from given filepath +// this is compatible with a yarn/lerna workspaces environment +const resolvePackageJsonPath = (filepath) => { + let packageJsonPath = resolve(dirname(filepath), PACKAGE_JSON); + // while the parent directory does not have package.json and not at root of path + while (!existsSync(packageJsonPath)) { + const prevPackageJsonPath = packageJsonPath; + // step up into parent directory + packageJsonPath = resolve(dirname(dirname(packageJsonPath)), PACKAGE_JSON); + // ensure not already at root + if (packageJsonPath === prevPackageJsonPath) { + throw new Error(`could not resolve ${PACKAGE_JSON} from ${filepath}`); + } + } + // found a package.json file + return packageJsonPath; +} + +module.exports = function versionTransform() { + return { + visitor: { + Identifier(path, { filename }) { + if (path.node.name === '__PACKAGE_JSON_VERSION__') { + // find nearest package.json file + const packagePath = resolvePackageJsonPath(filename); + // replace reference with version string + const { version } = require(packagePath); + path.replaceWithSourceString('"' + version + '"'); + } + }, + }, + }; +}; From 1ee409e23122892186b5694108fd95a7a76cf82a Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 15:54:28 -0700 Subject: [PATCH 10/16] Revert "Revert "use read-pkg-up dependency in babel plugin"" This reverts commit 9d9830fb6f692f33a0612270c753ec3518a39237. --- lib/babel-plugin-package-json-version.js | 33 ++++++------------------ 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/lib/babel-plugin-package-json-version.js b/lib/babel-plugin-package-json-version.js index f71dd6de033..fed395ead92 100644 --- a/lib/babel-plugin-package-json-version.js +++ b/lib/babel-plugin-package-json-version.js @@ -1,35 +1,18 @@ -const { resolve, sep, dirname } = require('path'); -const { existsSync } = require('fs'); - -const PACKAGE_JSON = 'package.json'; - -// returns path to closest package.json file while traversing up from given filepath -// this is compatible with a yarn/lerna workspaces environment -const resolvePackageJsonPath = (filepath) => { - let packageJsonPath = resolve(dirname(filepath), PACKAGE_JSON); - // while the parent directory does not have package.json and not at root of path - while (!existsSync(packageJsonPath)) { - const prevPackageJsonPath = packageJsonPath; - // step up into parent directory - packageJsonPath = resolve(dirname(dirname(packageJsonPath)), PACKAGE_JSON); - // ensure not already at root - if (packageJsonPath === prevPackageJsonPath) { - throw new Error(`could not resolve ${PACKAGE_JSON} from ${filepath}`); - } - } - // found a package.json file - return packageJsonPath; -} +const { dirname } = require('path'); +const readPkgUp = require('read-pkg-up'); module.exports = function versionTransform() { return { visitor: { Identifier(path, { filename }) { if (path.node.name === '__PACKAGE_JSON_VERSION__') { - // find nearest package.json file - const packagePath = resolvePackageJsonPath(filename); + // find and read nearest package.json file + const resolvedPackage = readPkgUp.sync({ cwd: dirname(filename) }); + if (!resolvedPackage) { + throw new Error(`could not resolve package.json from ${filepath}`); + } // replace reference with version string - const { version } = require(packagePath); + const { version } = resolvedPackage.packageJson; path.replaceWithSourceString('"' + version + '"'); } }, From 08f2ebcaff2576bd9abd5cfbd9296cb87f3a3de6 Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 15:55:23 -0700 Subject: [PATCH 11/16] useEffect AND use the local babel plugin to inject package version --- packages/@react-aria/utils/src/useId.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/@react-aria/utils/src/useId.ts b/packages/@react-aria/utils/src/useId.ts index 5d3c9aa4daf..673d6764635 100644 --- a/packages/@react-aria/utils/src/useId.ts +++ b/packages/@react-aria/utils/src/useId.ts @@ -15,9 +15,10 @@ import {useEffect, useLayoutEffect, useMemo, useState} from 'react'; let map: Map void> = new Map(); let id = 0; -// don't want to conflict with ids from v2, this will guarantee something unique +// don't want to conflict with ids from other instances of this module, this will *mostly* guarantee something unique // plus we'll know how many instances of this module are loaded on a page if there are more than one number ;) -let randomInstanceNumber = Math.round(Math.random() * 10000000000); +// NOTE: __PACKAGE_JSON_VERSION__ is injected by /lib/babel-plugin-package-json-version.js during babel transpilation +let packageVersion = __PACKAGE_JSON_VERSION__; /** * If a default is not provided, generate an id. @@ -28,13 +29,12 @@ export function useId(defaultId?: string): string { // preserve SSR rendering compatibility // only use the auto-generated id after component mounts client-side useEffect(() => { - const res = value || `react-aria-${randomInstanceNumber}-${++id}`; + const res = value || `react-aria-utils-${__PACKAGE_JSON_VERSION__}-${++id}`; map.set(res, setValue); setValue(res); }, [value]) return value; } - /** * Merges two ids. */ From 160db2851aacc7c3410d1a5a4bec54d0b468506b Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 16:29:13 -0700 Subject: [PATCH 12/16] useEffect with random number seed, no babel-plugin --- packages/@react-aria/utils/src/useId.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/@react-aria/utils/src/useId.ts b/packages/@react-aria/utils/src/useId.ts index 673d6764635..b9ece44c127 100644 --- a/packages/@react-aria/utils/src/useId.ts +++ b/packages/@react-aria/utils/src/useId.ts @@ -15,10 +15,9 @@ import {useEffect, useLayoutEffect, useMemo, useState} from 'react'; let map: Map void> = new Map(); let id = 0; -// don't want to conflict with ids from other instances of this module, this will *mostly* guarantee something unique +// don't want to conflict with ids from v2, this will guarantee something unique // plus we'll know how many instances of this module are loaded on a page if there are more than one number ;) -// NOTE: __PACKAGE_JSON_VERSION__ is injected by /lib/babel-plugin-package-json-version.js during babel transpilation -let packageVersion = __PACKAGE_JSON_VERSION__; +let randomInstanceNumber = Math.round(Math.random() * 10000000000); /** * If a default is not provided, generate an id. @@ -29,9 +28,11 @@ export function useId(defaultId?: string): string { // preserve SSR rendering compatibility // only use the auto-generated id after component mounts client-side useEffect(() => { - const res = value || `react-aria-utils-${__PACKAGE_JSON_VERSION__}-${++id}`; + const res = value || `react-aria-${randomInstanceNumber}-${++id}`; map.set(res, setValue); - setValue(res); + if (res !== value) { + setValue(res); + } }, [value]) return value; } From 5808bb6153ef2cdd798543b31b0f30cad837c90a Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 16:30:05 -0700 Subject: [PATCH 13/16] remove the local babel plugin --- babel.config.json | 3 +-- lib/babel-plugin-package-json-version.js | 21 --------------------- package.json | 1 - 3 files changed, 1 insertion(+), 24 deletions(-) delete mode 100644 lib/babel-plugin-package-json-version.js diff --git a/babel.config.json b/babel.config.json index 3b32117185a..c73d561f2f9 100644 --- a/babel.config.json +++ b/babel.config.json @@ -63,8 +63,7 @@ "@babel/plugin-proposal-export-namespace-from", "@babel/plugin-syntax-class-properties", "transform-glob-import", - "babel-plugin-macros", - "./lib/babel-plugin-package-json-version" + "babel-plugin-macros" ], "sourceType": "unambiguous" } diff --git a/lib/babel-plugin-package-json-version.js b/lib/babel-plugin-package-json-version.js deleted file mode 100644 index fed395ead92..00000000000 --- a/lib/babel-plugin-package-json-version.js +++ /dev/null @@ -1,21 +0,0 @@ -const { dirname } = require('path'); -const readPkgUp = require('read-pkg-up'); - -module.exports = function versionTransform() { - return { - visitor: { - Identifier(path, { filename }) { - if (path.node.name === '__PACKAGE_JSON_VERSION__') { - // find and read nearest package.json file - const resolvedPackage = readPkgUp.sync({ cwd: dirname(filename) }); - if (!resolvedPackage) { - throw new Error(`could not resolve package.json from ${filepath}`); - } - // replace reference with version string - const { version } = resolvedPackage.packageJson; - path.replaceWithSourceString('"' + version + '"'); - } - }, - }, - }; -}; diff --git a/package.json b/package.json index 0303720b4c5..fc49705e9bb 100644 --- a/package.json +++ b/package.json @@ -140,7 +140,6 @@ "react-dom": "^0.14 || ^15 || ^16", "react-overlays": "0.8.3", "react-test-renderer": "^16.9.0", - "read-pkg-up": "^7.0.1", "recursive-readdir": "^2.2.2", "regenerator-runtime": "0.13.3", "rimraf": "^2.6.3", From 276ea047fdd641ea927ece25d4a8f0a83a36d7b2 Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 19:10:05 -0700 Subject: [PATCH 14/16] update id in useId when defaultId changes --- packages/@react-aria/utils/src/useId.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/@react-aria/utils/src/useId.ts b/packages/@react-aria/utils/src/useId.ts index b9ece44c127..20d7f95fa96 100644 --- a/packages/@react-aria/utils/src/useId.ts +++ b/packages/@react-aria/utils/src/useId.ts @@ -24,16 +24,17 @@ let randomInstanceNumber = Math.round(Math.random() * 10000000000); * @param defaultId - Default component id. */ export function useId(defaultId?: string): string { - let [value, setValue] = useState(defaultId); + let [value, setValue] = useState(defaultId || ''); // preserve SSR rendering compatibility // only use the auto-generated id after component mounts client-side useEffect(() => { - const res = value || `react-aria-${randomInstanceNumber}-${++id}`; + const res = defaultId || value || `react-aria-${randomInstanceNumber}-${++id}`; map.set(res, setValue); if (res !== value) { setValue(res); } - }, [value]) + }, [defaultId, value]) + return value; } /** From ea4a7b7e2c5fe772254ed7d8ef2764c42f020655 Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 19:21:13 -0700 Subject: [PATCH 15/16] useEffect instead of useLayoutEffect in useSlotId --- packages/@react-aria/utils/src/useId.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@react-aria/utils/src/useId.ts b/packages/@react-aria/utils/src/useId.ts index 20d7f95fa96..3a98156cef4 100644 --- a/packages/@react-aria/utils/src/useId.ts +++ b/packages/@react-aria/utils/src/useId.ts @@ -66,7 +66,7 @@ export function mergeIds(a: string, b: string): string { */ export function useSlotId(): string { let [id, setId] = useState(useId()); - useLayoutEffect(() => { + useEffect(() => { let setCurr = map.get(id); if (setCurr && !document.getElementById(id)) { setId(null); From 5035c79c9a083d4676928df5b2afd4ac7addea14 Mon Sep 17 00:00:00 2001 From: Benjamin Allen Date: Thu, 13 Aug 2020 19:22:30 -0700 Subject: [PATCH 16/16] wait for id in useNumberField --- packages/@react-aria/numberfield/src/useNumberField.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/@react-aria/numberfield/src/useNumberField.ts b/packages/@react-aria/numberfield/src/useNumberField.ts index 1e4e887a78b..e8cb55a5fd4 100644 --- a/packages/@react-aria/numberfield/src/useNumberField.ts +++ b/packages/@react-aria/numberfield/src/useNumberField.ts @@ -114,6 +114,10 @@ export function useNumberField(props: NumberFieldProps, state: NumberFieldState, }); useEffect(() => { + if (!document.getElementById(inputId)) { + return () => {}; + } + const handleInputScrollWheel = e => { // If the input isn't supposed to receive input, do nothing. // TODO: add focus