Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

小程序页面组件 useDidShow触发问题 #10787

Closed
TheKonka opened this issue Dec 1, 2021 · 4 comments
Closed

小程序页面组件 useDidShow触发问题 #10787

TheKonka opened this issue Dec 1, 2021 · 4 comments
Labels
F-react Framework - React question Further information is requested T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@TheKonka
Copy link
Member

TheKonka commented Dec 1, 2021

相关平台

微信小程序

小程序基础库: 2.20.2
使用框架: React

复现步骤

小程序支持客户端和服务端 切换登录,因为小程序 tabbar list等限制,我选择对tabbar页面单独 建了个傀儡页, 目前 是 在傀儡页里 获取 storage判断是 客户端还是服务端登录,然后渲染 真正的客户端 或者 服务端 页面。

问题就是 比如 切换到 客户端 登录后,第一次 切到tabbar页面,渲染的是 客户端的页面,但是 触发的却是 服务端的useDidShow hook,我不清楚具体原因,求教。

傀儡页示例代码:

import React, { useState } from "react";
import Taro, { useDidShow } from "@tarojs/taro";
import Server from "@/src/pages/server/home/index";
import Customer from "@/src/pages/customer/index/index";
import TabBar from "@/src/components/custom-tab-bar";

const Index: React.FC = () => {
  const [isServer, setIsServer] = useState(() => Taro.getStorageSync("isServer"));
  console.log("tabbar-1", isServer);  
  useDidShow(() => {
    setIsServer(Taro.getStorageSync("isServer"));
  });
  console.log("tabbar-1-after", isServer);
  return (
    <>
      {isServer ? <Server /> : <Customer />}
      <TabBar tabBarIndex={1} />
    </>
  );
};

export default Index;

isServer 打印的都是空,页面也是 Customer ,但是 只触发了 Server 里的useDidShow 。
若 切换 服务端登录,第一次 进tabbar页面就相反,isServer为true,页面是 Server,但是 只触发了 Customer的useDidShow 。

期望结果

渲染的是 客户端的页面,触发客户端的useDidShow

实际结果

渲染的是 客户端的页面,触发服务端的useDidShow

环境信息

👽 Taro v3.3.15


  Taro CLI 3.3.15 environment info:
    System:
      OS: macOS 12.0.1
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 14.16.1 - /usr/local/bin/node
      Yarn: 1.22.15 - ~/.yarn/bin/yarn
      npm: 7.20.0 - /usr/local/bin/npm
    npmPackages:
      @tarojs/components: 3.3.15 => 3.3.15 
      @tarojs/mini-runner: 3.3.15 => 3.3.15 
      @tarojs/react: 3.3.15 => 3.3.15 
      @tarojs/runtime: 3.3.15 => 3.3.15 
      @tarojs/taro: 3.3.15 => 3.3.15 
      @tarojs/webpack-runner: 3.3.15 => 3.3.15 
      babel-preset-taro: 3.3.15 => 3.3.15 
      eslint-config-taro: 3.3.15 => 3.3.15 
      react: ^17.0.0 => 17.0.2 
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Dec 1, 2021
@Chen-jj
Copy link
Contributor

Chen-jj commented Dec 14, 2021

@konka-king 提供一下完整可复现的 demo 吧,看不出来。。

@Chen-jj Chen-jj added the question Further information is requested label Dec 14, 2021
@TheKonka
Copy link
Member Author

TheKonka commented Jan 23, 2022

不通过 usedidshow, 通过 redux 订阅更新方式 已解决

@zsytssk
Copy link

zsytssk commented Nov 11, 2022

@konka-king 提供一下完整可复现的 demo 吧,看不出来。。

3.5.3也有这个问题,所有通过条件判断后续显示的组件都会有这个问题。
麻烦把这个bug打开,我这里提供复现demo,https://github.com/zsytssk/taro-test/tree/bugUseDidShow

@yoyo837
Copy link
Contributor

yoyo837 commented Nov 11, 2022

@konka-king 提供一下完整可复现的 demo 吧,看不出来。。

3.5.3也有这个问题,所有通过条件判断后续显示的组件都会有这个问题。 麻烦把这个bug打开,我这里提供复现demo,https://github.com/zsytssk/taro-test/tree/bugUseDidShow

用上面的复现来个新的issue吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React question Further information is requested T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

4 participants