From c11289f872785bac589f4f98619c498e62ee9b40 Mon Sep 17 00:00:00 2001 From: jdecroock Date: Sat, 24 May 2025 11:35:42 +0200 Subject: [PATCH 1/2] Remove lifecycles from core --- compat/src/index.d.ts | 7 ------- demo/people/profile.tsx | 6 ++++-- src/diff/index.js | 21 --------------------- src/index-5.d.ts | 7 ------- src/index.d.ts | 7 ------- test/ts/preact.tsx | 17 ----------------- 6 files changed, 4 insertions(+), 61 deletions(-) diff --git a/compat/src/index.d.ts b/compat/src/index.d.ts index 093c7d0970..fa73cbe7ff 100644 --- a/compat/src/index.d.ts +++ b/compat/src/index.d.ts @@ -28,21 +28,14 @@ declare namespace preact { } export interface Component

{ - componentWillMount?(): void; componentDidMount?(): void; componentWillUnmount?(): void; getChildContext?(): object; - componentWillReceiveProps?(nextProps: Readonly

, nextContext: any): void; shouldComponentUpdate?( nextProps: Readonly

, nextState: Readonly, nextContext: any ): boolean; - componentWillUpdate?( - nextProps: Readonly

, - nextState: Readonly, - nextContext: any - ): void; getSnapshotBeforeUpdate?(oldProps: Readonly

, oldState: Readonly): any; componentDidUpdate?( previousProps: Readonly

, diff --git a/demo/people/profile.tsx b/demo/people/profile.tsx index fb18f568f5..5d5f900859 100644 --- a/demo/people/profile.tsx +++ b/demo/people/profile.tsx @@ -14,8 +14,10 @@ export class Profile extends Component { this.id = this.props.route; } - componentWillReceiveProps(props: ProfileProps) { - this.id = props.route; + componentDidUpdate(prevProps: ProfileProps) { + if (prevProps.route !== this.props.route) { + this.id = this.props.route; + } } render() { diff --git a/src/diff/index.js b/src/diff/index.js index d9a62cbae5..19e5e4f0d8 100644 --- a/src/diff/index.js +++ b/src/diff/index.js @@ -147,27 +147,10 @@ export function diff( // Invoke pre-render lifecycle methods if (isNew) { - if ( - isClassComponent && - newType.getDerivedStateFromProps == NULL && - c.componentWillMount != NULL - ) { - c.componentWillMount(); - } - if (isClassComponent && c.componentDidMount != NULL) { c._renderCallbacks.push(c.componentDidMount); } } else { - if ( - isClassComponent && - newType.getDerivedStateFromProps == NULL && - newProps !== oldProps && - c.componentWillReceiveProps != NULL - ) { - c.componentWillReceiveProps(newProps, componentContext); - } - if ( (!c._force && c.shouldComponentUpdate != NULL && @@ -207,10 +190,6 @@ export function diff( break outer; } - if (c.componentWillUpdate != NULL) { - c.componentWillUpdate(newProps, c._nextState, componentContext); - } - if (isClassComponent && c.componentDidUpdate != NULL) { c._renderCallbacks.push(() => { c.componentDidUpdate(oldProps, oldState, snapshot); diff --git a/src/index-5.d.ts b/src/index-5.d.ts index 1431b01f30..78614c2010 100644 --- a/src/index-5.d.ts +++ b/src/index-5.d.ts @@ -111,21 +111,14 @@ export type AnyComponent

= | ComponentConstructor; export interface Component

{ - componentWillMount?(): void; componentDidMount?(): void; componentWillUnmount?(): void; getChildContext?(): object; - componentWillReceiveProps?(nextProps: Readonly

, nextContext: any): void; shouldComponentUpdate?( nextProps: Readonly

, nextState: Readonly, nextContext: any ): boolean; - componentWillUpdate?( - nextProps: Readonly

, - nextState: Readonly, - nextContext: any - ): void; getSnapshotBeforeUpdate?(oldProps: Readonly

, oldState: Readonly): any; componentDidUpdate?( previousProps: Readonly

, diff --git a/src/index.d.ts b/src/index.d.ts index e6b8fd549e..e5417b68a1 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -111,21 +111,14 @@ export type AnyComponent

= | ComponentConstructor; export interface Component

{ - componentWillMount?(): void; componentDidMount?(): void; componentWillUnmount?(): void; getChildContext?(): object; - componentWillReceiveProps?(nextProps: Readonly

, nextContext: any): void; shouldComponentUpdate?( nextProps: Readonly

, nextState: Readonly, nextContext: any ): boolean; - componentWillUpdate?( - nextProps: Readonly

, - nextState: Readonly, - nextContext: any - ): void; getSnapshotBeforeUpdate?(oldProps: Readonly

, oldState: Readonly): any; componentDidUpdate?( previousProps: Readonly

, diff --git a/test/ts/preact.tsx b/test/ts/preact.tsx index c0fe2cfc08..43ce44427f 100644 --- a/test/ts/preact.tsx +++ b/test/ts/preact.tsx @@ -202,10 +202,6 @@ class ComponentWithLifecycle extends Component { return

Hi
; } - componentWillMount() { - console.log('componentWillMount'); - } - componentDidMount() { console.log('componentDidMount'); } @@ -214,11 +210,6 @@ class ComponentWithLifecycle extends Component { console.log('componentWillUnmount'); } - componentWillReceiveProps(nextProps: DummyProps, nextCtx: any) { - const { initialInput } = nextProps; - console.log('componentWillReceiveProps', initialInput, nextCtx); - } - shouldComponentUpdate( nextProps: DummyProps, nextState: DummyState, @@ -227,14 +218,6 @@ class ComponentWithLifecycle extends Component { return false; } - componentWillUpdate( - nextProps: DummyProps, - nextState: DummyState, - nextContext: any - ) { - console.log('componentWillUpdate', nextProps, nextState, nextContext); - } - componentDidUpdate( previousProps: DummyProps, previousState: DummyState, From 230e39a11933104a5ba016dbc18245803f94a9c8 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Sat, 24 May 2025 12:00:11 +0200 Subject: [PATCH 2/2] Temp add willUpdate back --- src/diff/index.js | 4 ++++ src/index-5.d.ts | 5 +++++ src/index.d.ts | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/src/diff/index.js b/src/diff/index.js index 19e5e4f0d8..b9031ad40d 100644 --- a/src/diff/index.js +++ b/src/diff/index.js @@ -190,6 +190,10 @@ export function diff( break outer; } + if (c.componentWillUpdate != NULL) { + c.componentWillUpdate(newProps, c._nextState, componentContext); + } + if (isClassComponent && c.componentDidUpdate != NULL) { c._renderCallbacks.push(() => { c.componentDidUpdate(oldProps, oldState, snapshot); diff --git a/src/index-5.d.ts b/src/index-5.d.ts index 78614c2010..b9ab2035b0 100644 --- a/src/index-5.d.ts +++ b/src/index-5.d.ts @@ -119,6 +119,11 @@ export interface Component

{ nextState: Readonly, nextContext: any ): boolean; + componentWillUpdate?( + nextProps: Readonly

, + nextState: Readonly, + nextContext: any + ): void; getSnapshotBeforeUpdate?(oldProps: Readonly

, oldState: Readonly): any; componentDidUpdate?( previousProps: Readonly

, diff --git a/src/index.d.ts b/src/index.d.ts index e5417b68a1..d9d9eaf393 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -119,6 +119,11 @@ export interface Component

{ nextState: Readonly, nextContext: any ): boolean; + componentWillUpdate?( + nextProps: Readonly

, + nextState: Readonly, + nextContext: any + ): void; getSnapshotBeforeUpdate?(oldProps: Readonly

, oldState: Readonly): any; componentDidUpdate?( previousProps: Readonly

,