NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
https://docs.taro.zone/
Other
35.36k stars 4.77k forks source link

3.6.6,componentDidHide在页面返回时,不触发 #13832

Closed L-x-C closed 1 year ago

L-x-C commented 1 year ago

相关平台

H5

浏览器版本: chrome 100 使用框架: React

复现步骤

建2个页面

import Taro from '@tarojs/taro';
import React from 'react';

export default class Test1 extends React.Component {
  state = {

  };

  componentDidHide() {
    console.log('hide11111')
  }

  componentDidShow() {
  }

  click() {
    Taro.navigateTo({
      url: '/pages/test/index2'
    })
  }

  render() {
    return (
      <>
        <button id='box' onClick={this.click}>点击去Test2</button>
      </>
    );
  }
}

import Taro from '@tarojs/taro';
import React from 'react';

export default class Test2 extends React.Component {
  state = {

  };

  componentDidHide() {
    console.log('hide2222')
  }

  componentDidShow() {
  }

  click() {
    Taro.navigateBack()
  }

  render() {
    return (
      <>
        <button id='box' onClick={this.click}>点击返回Test1</button>
      </>
    );
  }
}

从Test1点击按钮跳去Test2,再从Test2返回

期望结果

理论上应该触发hide11111和hide2222

实际结果

实际只触发了hide11111

环境信息

  Taro CLI 3.0.21 environment info:
    System:
      OS: macOS 13.3.1
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 11.15.0 - ~/.nvm/versions/node/v11.15.0/bin/node
      Yarn: 1.22.10 - ~/.nvm/versions/node/v11.15.0/bin/yarn
      npm: 6.7.0 - ~/.nvm/versions/node/v11.15.0/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.6 => 3.6.6
      @tarojs/components: 3.6.6 => 3.6.6
      @tarojs/mini-runner: 3.6.6 => 3.6.6
      @tarojs/react: 3.6.6 => 3.6.6
      @tarojs/runtime: 3.6.6 => 3.6.6
      @tarojs/taro: 3.6.6 => 3.6.6
      @tarojs/webpack-runner: 3.6.6 => 3.6.6
      babel-preset-taro: 3.6.6 => 3.6.6
      eslint-config-taro: 3.6.6 => 3.6.6
      react: ^16.10.0 => 16.14.0
      taro-ui: 3.1.0-beta.4 => 3.1.0-beta.4
    npmGlobalPackages:
      typescript: 5.0.2
ZakaryCode commented 1 year ago

页面2是被销毁了,实际不应该执行 hide 生命周期