Skip to content

Commit a59b414

Browse files
committed
build: fix build
1 parent 71317e4 commit a59b414

5 files changed

Lines changed: 249 additions & 0 deletions

File tree

config/vite.config.base.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ export default defineConfig({
128128
find: 'vue-i18n',
129129
replacement: 'vue-i18n/dist/vue-i18n.cjs.js', // Resolve the i18n warning issue
130130
},
131+
{
132+
find: 'hoist-non-react-statics',
133+
replacement: resolve(__dirname, '../src/perses-dashboard/vendor/hoist-non-react-statics'),
134+
},
135+
{
136+
find: 'react-is',
137+
replacement: resolve(__dirname, '../src/perses-dashboard/vendor/react-is'),
138+
},
131139
{
132140
find: 'vue',
133141
replacement: 'vue/dist/vue.esm-bundler.js', // compile template

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"react": "^18.3.1",
103103
"react-dom": "^18.3.1",
104104
"react-router-dom": "^6.26.2",
105+
"react-is": "^18.3.1",
105106
"sortablejs": "^1.15.0",
106107
"sql-formatter": "^12.1.3",
107108
"stylelint-config-rational-order-fix": "^0.1.9",

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
const REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref')
2+
const REACT_MEMO_TYPE = Symbol.for('react.memo')
3+
4+
const REACT_STATICS: Record<string, boolean> = {
5+
childContextTypes: true,
6+
contextType: true,
7+
contextTypes: true,
8+
defaultProps: true,
9+
displayName: true,
10+
getDefaultProps: true,
11+
getDerivedStateFromError: true,
12+
getDerivedStateFromProps: true,
13+
mixins: true,
14+
propTypes: true,
15+
type: true,
16+
}
17+
18+
const KNOWN_STATICS: Record<string, boolean> = {
19+
name: true,
20+
length: true,
21+
prototype: true,
22+
caller: true,
23+
callee: true,
24+
arguments: true,
25+
arity: true,
26+
}
27+
28+
const FORWARD_REF_STATICS: Record<string, boolean> = {
29+
$$typeof: true,
30+
render: true,
31+
defaultProps: true,
32+
displayName: true,
33+
propTypes: true,
34+
}
35+
36+
const MEMO_STATICS: Record<string, boolean> = {
37+
$$typeof: true,
38+
compare: true,
39+
defaultProps: true,
40+
displayName: true,
41+
propTypes: true,
42+
type: true,
43+
}
44+
45+
const TYPE_STATICS: Record<string, Record<string, boolean>> = {}
46+
TYPE_STATICS[REACT_FORWARD_REF_TYPE as unknown as string] = FORWARD_REF_STATICS
47+
48+
function getStatics(component: any): Record<string, boolean> {
49+
if (component && component.$$typeof === REACT_MEMO_TYPE) {
50+
return MEMO_STATICS
51+
}
52+
return TYPE_STATICS[component?.['$$typeof']] || REACT_STATICS
53+
}
54+
55+
const defineProperty = Object.defineProperty
56+
const getOwnPropertyNames = Object.getOwnPropertyNames
57+
const getOwnPropertySymbols = Object.getOwnPropertySymbols
58+
const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor
59+
const getPrototypeOf = Object.getPrototypeOf
60+
const objectPrototype = Object.prototype
61+
62+
export default function hoistNonReactStatics(
63+
targetComponent: any,
64+
sourceComponent: any,
65+
blacklist?: Record<string, boolean>
66+
) {
67+
if (typeof sourceComponent !== 'string') {
68+
if (objectPrototype) {
69+
const inheritedComponent = getPrototypeOf(sourceComponent)
70+
if (inheritedComponent && inheritedComponent !== objectPrototype) {
71+
hoistNonReactStatics(targetComponent, inheritedComponent, blacklist)
72+
}
73+
}
74+
75+
let keys: Array<string | symbol> = getOwnPropertyNames(sourceComponent)
76+
77+
if (getOwnPropertySymbols) {
78+
keys = keys.concat(getOwnPropertySymbols(sourceComponent))
79+
}
80+
81+
const targetStatics = getStatics(targetComponent)
82+
const sourceStatics = getStatics(sourceComponent)
83+
84+
for (let i = 0; i < keys.length; ++i) {
85+
const key = keys[i] as string
86+
if (
87+
!KNOWN_STATICS[key] &&
88+
!(blacklist && blacklist[key]) &&
89+
!(sourceStatics && sourceStatics[key]) &&
90+
!(targetStatics && targetStatics[key])
91+
) {
92+
const descriptor = getOwnPropertyDescriptor(sourceComponent, key)
93+
try {
94+
defineProperty(targetComponent, key, descriptor as PropertyDescriptor)
95+
} catch {
96+
// ignore read-only properties
97+
}
98+
}
99+
}
100+
}
101+
102+
return targetComponent
103+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
const hasSymbol = typeof Symbol === 'function' && Symbol.for
2+
3+
export const REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7
4+
export const REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca
5+
export const REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb
6+
export const REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc
7+
export const REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2
8+
export const REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd
9+
export const REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace
10+
export const REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0
11+
export const REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1
12+
export const REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8
13+
export const REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3
14+
export const REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4
15+
export const REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7
16+
17+
export function typeOf(object: any) {
18+
if (typeof object === 'object' && object !== null) {
19+
const { $$typeof } = object
20+
switch ($$typeof) {
21+
case REACT_ELEMENT_TYPE: {
22+
const { type } = object
23+
switch (type) {
24+
case REACT_FRAGMENT_TYPE:
25+
case REACT_PROFILER_TYPE:
26+
case REACT_STRICT_MODE_TYPE:
27+
case REACT_SUSPENSE_TYPE:
28+
return type
29+
default: {
30+
const typeOfType = type && type.$$typeof
31+
switch (typeOfType) {
32+
case REACT_CONTEXT_TYPE:
33+
case REACT_FORWARD_REF_TYPE:
34+
case REACT_PROVIDER_TYPE:
35+
case REACT_MEMO_TYPE:
36+
case REACT_LAZY_TYPE:
37+
return typeOfType
38+
default:
39+
return $$typeof
40+
}
41+
}
42+
}
43+
}
44+
case REACT_PORTAL_TYPE:
45+
return $$typeof
46+
default:
47+
return $$typeof
48+
}
49+
}
50+
return undefined
51+
}
52+
53+
export const AsyncMode = 0xead5
54+
export const ConcurrentMode = 0xead5
55+
export const ContextConsumer = REACT_CONTEXT_TYPE
56+
export const ContextProvider = REACT_PROVIDER_TYPE
57+
export const Element = REACT_ELEMENT_TYPE
58+
export const ForwardRef = REACT_FORWARD_REF_TYPE
59+
export const Fragment = REACT_FRAGMENT_TYPE
60+
export const Lazy = REACT_LAZY_TYPE
61+
export const Memo = REACT_MEMO_TYPE
62+
export const Portal = REACT_PORTAL_TYPE
63+
export const Profiler = REACT_PROFILER_TYPE
64+
export const StrictMode = REACT_STRICT_MODE_TYPE
65+
export const Suspense = REACT_SUSPENSE_TYPE
66+
67+
export function isValidElementType(type: any) {
68+
return (
69+
typeof type === 'string' ||
70+
typeof type === 'function' ||
71+
type === REACT_FRAGMENT_TYPE ||
72+
type === REACT_PROFILER_TYPE ||
73+
type === REACT_STRICT_MODE_TYPE ||
74+
type === REACT_SUSPENSE_TYPE ||
75+
type === REACT_SUSPENSE_LIST_TYPE ||
76+
(typeof type === 'object' &&
77+
type !== null &&
78+
(type.$$typeof === REACT_LAZY_TYPE ||
79+
type.$$typeof === REACT_MEMO_TYPE ||
80+
type.$$typeof === REACT_PROVIDER_TYPE ||
81+
type.$$typeof === REACT_CONTEXT_TYPE ||
82+
type.$$typeof === REACT_FORWARD_REF_TYPE ||
83+
type.$$typeof === REACT_SCOPE_TYPE))
84+
)
85+
}
86+
87+
export function isElement(object: any) {
88+
return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE
89+
}
90+
91+
export function isFragment(object: any) {
92+
return typeOf(object) === REACT_FRAGMENT_TYPE
93+
}
94+
95+
export function isMemo(object: any) {
96+
return typeOf(object) === REACT_MEMO_TYPE
97+
}
98+
99+
export function isLazy(object: any) {
100+
return typeOf(object) === REACT_LAZY_TYPE
101+
}
102+
103+
export function isForwardRef(object: any) {
104+
return typeOf(object) === REACT_FORWARD_REF_TYPE
105+
}
106+
107+
export function isContextConsumer(object: any) {
108+
return typeOf(object) === REACT_CONTEXT_TYPE
109+
}
110+
111+
export function isContextProvider(object: any) {
112+
return typeOf(object) === REACT_PROVIDER_TYPE
113+
}
114+
115+
export function isPortal(object: any) {
116+
return typeOf(object) === REACT_PORTAL_TYPE
117+
}
118+
119+
export function isProfiler(object: any) {
120+
return typeOf(object) === REACT_PROFILER_TYPE
121+
}
122+
123+
export function isStrictMode(object: any) {
124+
return typeOf(object) === REACT_STRICT_MODE_TYPE
125+
}
126+
127+
export function isSuspense(object: any) {
128+
return typeOf(object) === REACT_SUSPENSE_TYPE
129+
}

0 commit comments

Comments
 (0)