mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
fix: inert value in next15 (#4491)
* feat: add post install * feat: add postinstall * feat: add postinstall * fix: type * fix: type * fix: next version * chore(changeset): update package name --------- Co-authored-by: աӄա <wingkwong.code@gmail.com>
This commit is contained in:
parent
12a5c15699
commit
7402e00b62
5
.changeset/smart-eagles-hope.md
Normal file
5
.changeset/smart-eagles-hope.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@heroui/shared-utils": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Tabs with prop destroyInactiveTabPanel error in nextjs15(#4344)
|
||||||
@ -1,4 +1,4 @@
|
|||||||
# @heroui/system
|
# @heroui/shared-utils
|
||||||
|
|
||||||
A Quick description of the component
|
A Quick description of the component
|
||||||
|
|
||||||
@ -7,9 +7,9 @@ A Quick description of the component
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
yarn add @heroui/system
|
yarn add @heroui/shared-utils
|
||||||
# or
|
# or
|
||||||
npm i @heroui/system
|
npm i @heroui/shared-utils
|
||||||
```
|
```
|
||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
@ -18,6 +18,16 @@ Yes please! See the
|
|||||||
[contributing guidelines](https://github.com/heroui-inc/heroui/blob/master/CONTRIBUTING.md)
|
[contributing guidelines](https://github.com/heroui-inc/heroui/blob/master/CONTRIBUTING.md)
|
||||||
for details.
|
for details.
|
||||||
|
|
||||||
|
## File structure
|
||||||
|
|
||||||
|
```
|
||||||
|
src/
|
||||||
|
├── common/ # Common utilities for all React versions
|
||||||
|
└── demi/ # Demi utilities for different React versions
|
||||||
|
├── react18/
|
||||||
|
└── react19/
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
This project is licensed under the terms of the
|
This project is licensed under the terms of the
|
||||||
|
|||||||
@ -11,7 +11,8 @@
|
|||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist",
|
||||||
|
"scripts"
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
@ -25,13 +26,15 @@
|
|||||||
"url": "https://github.com/heroui-inc/heroui/issues"
|
"url": "https://github.com/heroui-inc/heroui/issues"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"postinstall": "node -e \"try{require('./scripts/postinstall.js')}catch(e){}\"",
|
||||||
"build": "tsup src --dts",
|
"build": "tsup src --dts",
|
||||||
"dev": "pnpm build:fast --watch",
|
"dev": "pnpm build:fast --watch",
|
||||||
"clean": "rimraf dist .turbo",
|
"clean": "rimraf dist .turbo",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"build:fast": "tsup src",
|
"build:fast": "tsup src",
|
||||||
"prepack": "clean-package",
|
"prepack": "clean-package",
|
||||||
"postpack": "clean-package restore"
|
"postpack": "clean-package restore",
|
||||||
|
"postbuild": "npm run postinstall"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"clean-package": "2.2.0"
|
"clean-package": "2.2.0"
|
||||||
@ -43,6 +46,8 @@
|
|||||||
"format": [
|
"format": [
|
||||||
"cjs",
|
"cjs",
|
||||||
"esm"
|
"esm"
|
||||||
]
|
],
|
||||||
|
"splitting": false,
|
||||||
|
"entry": ["src/demi/react18", "src/demi/react19"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
41
packages/utilities/shared-utils/scripts/postinstall.js
Normal file
41
packages/utilities/shared-utils/scripts/postinstall.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
const path = require('path')
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
|
function tryRequirePkg(pkg) {
|
||||||
|
try {
|
||||||
|
return require(pkg);
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyDemiDir(dir) {
|
||||||
|
const src = path.join(__dirname, '..', 'dist', 'demi', dir)
|
||||||
|
const dest = path.join(__dirname, '..', 'dist')
|
||||||
|
|
||||||
|
fs.cpSync(src, dest, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
function modifyDts(path) {
|
||||||
|
const dts = fs.readFileSync(path, 'utf8')
|
||||||
|
const modifiedDts = dts.replace(/\.\.\/\.\.\/common/g, './common')
|
||||||
|
|
||||||
|
fs.writeFileSync(path, modifiedDts, 'utf8')
|
||||||
|
}
|
||||||
|
|
||||||
|
function postinstall() {
|
||||||
|
const nextjs = tryRequirePkg('next/package.json')
|
||||||
|
const react = tryRequirePkg('react/package.json')
|
||||||
|
const nextjsVersion = Number((nextjs?.version || '').split('.')[0])
|
||||||
|
const reactVersion = Number((react?.version || '').split('.')[0])
|
||||||
|
|
||||||
|
if (reactVersion === 18 && nextjsVersion < 15) {
|
||||||
|
copyDemiDir('react18')
|
||||||
|
} else {
|
||||||
|
copyDemiDir('react19')
|
||||||
|
}
|
||||||
|
|
||||||
|
modifyDts(path.join(__dirname, '..', 'dist', 'index.d.ts'))
|
||||||
|
}
|
||||||
|
|
||||||
|
postinstall();
|
||||||
@ -1,5 +1,3 @@
|
|||||||
import React from "react";
|
|
||||||
|
|
||||||
type Args<T extends Function> = T extends (...args: infer R) => any ? R : never;
|
type Args<T extends Function> = T extends (...args: infer R) => any ? R : never;
|
||||||
|
|
||||||
type AnyFunction<T = any> = (...args: T[]) => any;
|
type AnyFunction<T = any> = (...args: T[]) => any;
|
||||||
@ -391,30 +389,3 @@ export const intersectionBy = <T>(...args: [...arrays: T[][], iteratee: Iteratee
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the current React version is 19.x.x
|
|
||||||
*
|
|
||||||
* @returns {boolean} - Returns `true` if the React major version is 19, otherwise returns `false`.
|
|
||||||
*/
|
|
||||||
export const isReact19 = (): boolean => {
|
|
||||||
return React.version.split(".")[0] === "19";
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an appropriate value for the `inert` attribute based on the React version.
|
|
||||||
*
|
|
||||||
* In React 19, the attribute `inert` is a boolean. In versions prior to 19, the attribute
|
|
||||||
* behaves differently: setting `inert=""` will make it `true`, and `inert=undefined` will make it `false`.
|
|
||||||
*
|
|
||||||
* @param {boolean} v - The desired boolean state for the `inert` attribute.
|
|
||||||
* @returns {boolean | string | undefined} - Depending on the React version:
|
|
||||||
* - Returns `boolean` if React version is 19 (the input value `v` directly).
|
|
||||||
* - Returns `string` (empty string) if `v` is `true` in older React versions.
|
|
||||||
* - Returns `undefined` if `v` is `false` in older React versions.
|
|
||||||
*
|
|
||||||
* @see {@link https://github.com/facebook/react/issues/17157} for more details on the behavior in older React versions.
|
|
||||||
*/
|
|
||||||
export const getInertValue = (v: boolean): boolean | string | undefined => {
|
|
||||||
return isReact19() ? v : v ? "" : undefined;
|
|
||||||
};
|
|
||||||
11
packages/utilities/shared-utils/src/common/index.ts
Normal file
11
packages/utilities/shared-utils/src/common/index.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
export * from "./assertion";
|
||||||
|
export * from "./clsx";
|
||||||
|
export * from "./object";
|
||||||
|
export * from "./text";
|
||||||
|
export * from "./dimensions";
|
||||||
|
export * from "./functions";
|
||||||
|
export * from "./numbers";
|
||||||
|
export * from "./console";
|
||||||
|
export * from "./types";
|
||||||
|
export * from "./dates";
|
||||||
|
export * from "./regex";
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* Returns an appropriate value for the `inert` attribute based on the React version.
|
||||||
|
*
|
||||||
|
* In React 19, the attribute `inert` is a boolean. In versions prior to 19, the attribute
|
||||||
|
* behaves differently: setting `inert=""` will make it `true`, and `inert=undefined` will make it `false`.
|
||||||
|
*
|
||||||
|
* @param {boolean} v - The desired boolean state for the `inert` attribute.
|
||||||
|
* @returns {boolean | string | undefined} - Depending on the React version:
|
||||||
|
* - Returns `boolean` if React version is 19 (the input value `v` directly).
|
||||||
|
* - Returns `string` (empty string) if `v` is `true` in older React versions.
|
||||||
|
* - Returns `undefined` if `v` is `false` in older React versions.
|
||||||
|
*
|
||||||
|
* @see {@link https://github.com/facebook/react/issues/17157} for more details on the behavior in older React versions.
|
||||||
|
*/
|
||||||
|
export const getInertValue = (v: boolean): boolean | string | undefined => {
|
||||||
|
return v ? "" : undefined;
|
||||||
|
};
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
export * from "./getInertValue";
|
||||||
|
|
||||||
|
export * from "../../common";
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* Returns an appropriate value for the `inert` attribute based on the React version.
|
||||||
|
*
|
||||||
|
* In React 19, the attribute `inert` is a boolean. In versions prior to 19, the attribute
|
||||||
|
* behaves differently: setting `inert=""` will make it `true`, and `inert=undefined` will make it `false`.
|
||||||
|
*
|
||||||
|
* @param {boolean} v - The desired boolean state for the `inert` attribute.
|
||||||
|
* @returns {boolean | string | undefined} - Depending on the React version:
|
||||||
|
* - Returns `boolean` if React version is 19 (the input value `v` directly).
|
||||||
|
* - Returns `string` (empty string) if `v` is `true` in older React versions.
|
||||||
|
* - Returns `undefined` if `v` is `false` in older React versions.
|
||||||
|
*
|
||||||
|
* @see {@link https://github.com/facebook/react/issues/17157} for more details on the behavior in older React versions.
|
||||||
|
*/
|
||||||
|
export const getInertValue = (v: boolean): boolean | string | undefined => {
|
||||||
|
return v;
|
||||||
|
};
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
export * from "./getInertValue";
|
||||||
|
|
||||||
|
export * from "../../common";
|
||||||
@ -1,11 +1,5 @@
|
|||||||
export * from "./assertion";
|
/**
|
||||||
export * from "./clsx";
|
* For Development
|
||||||
export * from "./object";
|
*/
|
||||||
export * from "./text";
|
export * from "./common";
|
||||||
export * from "./dimensions";
|
export * from "./demi/react18";
|
||||||
export * from "./functions";
|
|
||||||
export * from "./numbers";
|
|
||||||
export * from "./console";
|
|
||||||
export * from "./types";
|
|
||||||
export * from "./dates";
|
|
||||||
export * from "./regex";
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user