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 and felixpalmer committed Nov 8, 2024
1 parent 2aa3706 commit fab1b88
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 @@ -10,7 +10,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 @@ -62,6 +62,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 fab1b88

Please sign in to comment.