@@ -62,6 +62,8 @@ export function diff(
62
62
try {
63
63
let c , isNew , oldProps , oldState , snapshot , clearProcessingException ;
64
64
let newProps = newVNode . props ;
65
+ const isClassComponent =
66
+ 'prototype' in newType && newType . prototype . render ;
65
67
66
68
// Necessary for createContext api. Setting this property will pass
67
69
// the context value as `this.context` just for this component.
@@ -79,7 +81,7 @@ export function diff(
79
81
clearProcessingException = c . _processingException = c . _pendingError ;
80
82
} else {
81
83
// Instantiate the new component
82
- if ( 'prototype' in newType && newType . prototype . render ) {
84
+ if ( isClassComponent ) {
83
85
// @ts -expect-error The check above verifies that newType is suppose to be constructed
84
86
newVNode . _component = c = new newType ( newProps , componentContext ) ; // eslint-disable-line new-cap
85
87
} else {
@@ -103,11 +105,11 @@ export function diff(
103
105
}
104
106
105
107
// Invoke getDerivedStateFromProps
106
- if ( c . _nextState == null ) {
108
+ if ( isClassComponent && c . _nextState == null ) {
107
109
c . _nextState = c . state ;
108
110
}
109
111
110
- if ( newType . getDerivedStateFromProps != null ) {
112
+ if ( isClassComponent && newType . getDerivedStateFromProps != null ) {
111
113
if ( c . _nextState == c . state ) {
112
114
c . _nextState = assign ( { } , c . _nextState ) ;
113
115
}
@@ -125,17 +127,19 @@ export function diff(
125
127
// Invoke pre-render lifecycle methods
126
128
if ( isNew ) {
127
129
if (
130
+ isClassComponent &&
128
131
newType . getDerivedStateFromProps == null &&
129
132
c . componentWillMount != null
130
133
) {
131
134
c . componentWillMount ( ) ;
132
135
}
133
136
134
- if ( c . componentDidMount != null ) {
137
+ if ( isClassComponent && c . componentDidMount != null ) {
135
138
c . _renderCallbacks . push ( c . componentDidMount ) ;
136
139
}
137
140
} else {
138
141
if (
142
+ isClassComponent &&
139
143
newType . getDerivedStateFromProps == null &&
140
144
newProps !== oldProps &&
141
145
c . componentWillReceiveProps != null
@@ -186,7 +190,7 @@ export function diff(
186
190
c . componentWillUpdate ( newProps , c . _nextState , componentContext ) ;
187
191
}
188
192
189
- if ( c . componentDidUpdate != null ) {
193
+ if ( isClassComponent && c . componentDidUpdate != null ) {
190
194
c . _renderCallbacks . push ( ( ) => {
191
195
c . componentDidUpdate ( oldProps , oldState , snapshot ) ;
192
196
} ) ;
@@ -200,7 +204,7 @@ export function diff(
200
204
201
205
let renderHook = options . _render ,
202
206
count = 0 ;
203
- if ( 'prototype' in newType && newType . prototype . render ) {
207
+ if ( isClassComponent ) {
204
208
c . state = c . _nextState ;
205
209
c . _dirty = false ;
206
210
@@ -231,7 +235,7 @@ export function diff(
231
235
globalContext = assign ( assign ( { } , globalContext ) , c . getChildContext ( ) ) ;
232
236
}
233
237
234
- if ( ! isNew && c . getSnapshotBeforeUpdate != null ) {
238
+ if ( isClassComponent && ! isNew && c . getSnapshotBeforeUpdate != null ) {
235
239
snapshot = c . getSnapshotBeforeUpdate ( oldProps , oldState ) ;
236
240
}
237
241
0 commit comments