Repository navigation
fix(core): 子应用 location.href 跳转后不再销毁 sandbox,修复非降级模式下容器空白、无法后退恢复 - #1124
Merged
Merged
Conversation
v2.0.0 起重建模式的 wujie-app disconnect 改为 destroy,而 location.href 跳转时 wujie-app 正是被跳转后的 iframe 替换下来的:destroy 清空容器连带清掉新 iframe,sandbox 被销毁后浏览器 后退也无法恢复原应用。hrefFlag 为 true 时恢复为 unmount(unmount 本身已跳过 hrefFlag 下的 生命周期卸载与 DOM 清理)。 Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
从 v2.0.0 开始,非降级模式下子应用执行
location.href = "..."后,容器一片空白,浏览器后退也无法恢复原应用。原因
location.href跳转时,wujie 会用一个渲染目标地址的新 iframe 替换掉<wujie-app>,同时保留 sandbox(hrefFlag),用户后退时再把<wujie-app>放回去。7bfd3c9 之后,重建模式(非保活、没有做生命周期改造)下
<wujie-app>一旦 disconnect 就会执行sandbox.destroy():destroy()会清空容器,刚插入的新 iframe 也被一起清掉;修复
handleWujieAppDisconnect中,hrefFlag为 true 时不执行 destroy,改为 unmount,与 v2.0.0 之前一致。unmount()本来就会在hrefFlag为 true 时跳过子应用的生命周期卸载和 DOM 清理。验证
handleWujieAppDisconnect.test.ts新增「重建模式下 href 跳转只 unmount」的用例。location.replace/location.assign跳转会破坏沙箱的问题,在 #575 中处理。