Skip to content

Commit

Permalink
Avoid polluting function prototype in createPropsPrototypeAndTypes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
marsy-invests authored Nov 4, 2024
1 parent c7f1a66 commit 0b70ac2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion modules/core/src/lifecycle/create-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ASYNC_DEFAULTS_SYMBOL
} from './constants';
import {StatefulComponentProps} from './component';
import type Component from './component';
import Component from './component';

// Create a property object
export function createProps<PropsT extends {}>(
Expand Down Expand Up @@ -66,6 +66,13 @@ const MergedDefaultPropsCacheKey = '_mergedDefaultProps';
// Return precalculated defaultProps and propType objects if available
// build them if needed
function getPropsPrototype(componentClass, extensions?: any[]) {
// Bail out if we're not looking at a component - for two reasons:
// 1. There's no reason for an ancestor of component to have props
// 2. If we don't bail out, we'll follow the prototype chain all the way back to the global
// function prototype and add _mergedDefaultProps to it, which may break other frameworks
// (e.g. the react-three-fiber reconciler)
if (!(componentClass instanceof Component.constructor)) return {};

// A string that uniquely identifies the extensions involved
let cacheKey = MergedDefaultPropsCacheKey;
if (extensions) {
Expand Down

0 comments on commit 0b70ac2

Please sign in to comment.