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

preload 数据在路由切换时没有清除,其它页面也能获取到 #16930

Open
zhang0ZGC opened this issue Nov 25, 2024 · 1 comment
Open

Comments

@zhang0ZGC
Copy link

zhang0ZGC commented Nov 25, 2024

相关平台

微信小程序

复现仓库

https://github.com/zhang0ZGC/taro3-playground.git

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

复现步骤

  1. 在PageA点击按钮,使用 preload API预加载数据,跳转到PageB;
  2. B打印在 PageA 设置的预加载数据,点击返回按钮,返回A
  3. PageA 任然会显示之前设置的数据

期望结果

预加载数据只在在PageB显示

实际结果

只要不重新调用preload,在所有页面都会访问到之前设置的preloadData,容易导致数据错乱

image

环境信息

👽 Taro v3.6.35


  Taro CLI 3.6.35 environment info:
    System:
      OS: Windows 10 10.0.19045
    Binaries:
      Node: 18.20.4 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.22.5 - D:\Program Files (x86)\Yarn\bin\yarn.CMD
      npm: 10.7.0 - C:\Program Files\nodejs\npm.CMD
    npmPackages:
      @tarojs/cli: 3.6.35 => 3.6.35
      @tarojs/components: 3.6.35 => 3.6.35
      @tarojs/helper: 3.6.35 => 3.6.35
      @tarojs/plugin-framework-react: 3.6.35 => 3.6.35
      @tarojs/plugin-platform-alipay: 3.6.35 => 3.6.35
      @tarojs/plugin-platform-h5: 3.6.35 => 3.6.35
      @tarojs/plugin-platform-jd: 3.6.35 => 3.6.35
      @tarojs/plugin-platform-qq: 3.6.35 => 3.6.35
      @tarojs/plugin-platform-swan: 3.6.35 => 3.6.35
      @tarojs/plugin-platform-tt: 3.6.35 => 3.6.35
      @tarojs/plugin-platform-weapp: 3.6.35 => 3.6.35
      @tarojs/react: 3.6.35 => 3.6.35
      @tarojs/runtime: 3.6.35 => 3.6.35
      @tarojs/shared: 3.6.35 => 3.6.35
      @tarojs/taro: 3.6.35 => 3.6.35
      @tarojs/taro-loader: 3.6.35 => 3.6.35
      @tarojs/webpack5-runner: 3.6.35 => 3.6.35
      babel-preset-taro: 3.6.35 => 3.6.35
      eslint-config-taro: 3.6.35 => 3.6.35
      react: ^18.0.0 => 18.3.1
@zhang0ZGC
Copy link
Author

zhang0ZGC commented Nov 27, 2024

我学乖了,读取后就立即清除😭

看代码 Taro.Current 这个对象的内存地址是始终不变的,页面切换不会创建一个新的 Instance,只是把 Taro.Current 对象下的 page, router 等属性修改一下,所以 preloadData 如果不重置就会一直存在

This was referenced Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant