Skip to content

Comments

fix(miniapp-runtime): enter same page twice then exit should not throw error#7104

Merged
XGHeaven merged 1 commit intorelease/nextfrom
fix/miniapp-twice-page
Jun 4, 2025
Merged

fix(miniapp-runtime): enter same page twice then exit should not throw error#7104
XGHeaven merged 1 commit intorelease/nextfrom
fix/miniapp-twice-page

Conversation

@XGHeaven
Copy link
Collaborator

@XGHeaven XGHeaven commented Jun 4, 2025

小程序先进入同一个页面两次,然后退出,此时触发生命周期事件会报错。
主要由两个原因:

  • 页面的 id 使用的是路径,会导致同一个页面打开多次的时候冲突,从而让上一个页面退出后把后一个页面的事件存储实例也清除了。解决方式就是给 id 添加一个时间戳,保证每个页面的唯一性
  • 在触发生命周期的方法中,没有正确判断为空的情况。解决方法是判空

@XGHeaven XGHeaven requested review from ChrisCindy and ClarkXia June 4, 2025 12:56
@ClarkXia ClarkXia requested review from ClarkXia and Copilot and removed request for ChrisCindy and ClarkXia June 4, 2025 12:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an error when entering the same miniapp page twice and then exiting by ensuring each page has a unique id and guarding against null lifecycle events.

  • Updated unique id generation in common.ts by appending a timestamp to guarantee uniqueness.
  • Refactored hooks.ts to use React's useRef for consistent page instance management during lifecycle events.
  • Added a changeset entry to document the patch.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/miniapp-runtime/src/dsl/common.ts Appended a timestamp to options for generating a unique page id.
packages/miniapp-runtime/src/app/hooks.ts Refactored instance retrieval using a useRef to better manage page lifecycle events.
.changeset/six-zebras-sniff.md Added changeset metadata to record the patch.
Comments suppressed due to low confidence (2)

packages/miniapp-runtime/src/dsl/common.ts:133

  • [nitpick] Consider adding a comment to explain the purpose of introducing '$iceTimestamp' to assist future maintainers and update any related tests if needed.
const uniqueOptions = Object.assign({}, options, { $iceTimestamp: Date.now() });

packages/miniapp-runtime/src/app/hooks.ts:22

  • [nitpick] Adding a brief comment on the use of 'instRef' for storing the page instance can improve clarity during cleanup in the lifecycle hook.
let inst = instRef.current = getPageInstance(id);

@ClarkXia ClarkXia requested a review from ChrisCindy June 4, 2025 12:57
@XGHeaven XGHeaven merged commit d27ad76 into release/next Jun 4, 2025
10 checks passed
@XGHeaven XGHeaven deleted the fix/miniapp-twice-page branch June 4, 2025 13:11
@ClarkXia ClarkXia mentioned this pull request Jun 23, 2025
7 tasks
ClarkXia added a commit that referenced this pull request Jun 24, 2025
* fix: jsxplugs transform (#7076)

* fix: jsxplugs transform

* chore: change set

* Feat: add support for custom loaders in rspack configuration (#7078)

* feat: add support for custom loaders in rspack configuration

* chore: changeset

* fix: miniapp using absolute path to match route manifest (#7095)

* fix(miniapp-runtime): enter same page twice then exit should not throw error (#7104)

* fix: rename dropLog to dropLogLevel  in config.md (#7103)

* chore: update @swc/helpers to 0.5.17 (#7106)

* Fix/provide (#7097)

* feat: parse inject file

* feat: compileIncludes

* chore: change set

* feat: getexportsvariable

* chore: update versions (#7077)

---------

Co-authored-by: Homyee King <HomyeeKing@gmail.com>
Co-authored-by: XGHeaven <xgheaven@gmail.com>
Co-authored-by: Frank <405267330@qq.com>
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

Successfully merging this pull request may close these issues.

3 participants