Skip to content

fix(runtime-vapor): detach effect scope & component instance #174

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

Merged
merged 2 commits into from
Apr 16, 2024

Conversation

LittleSound
Copy link
Member

The existing setCurrentInstance will set instance.scope.on() internally and instance.scope.off() when calling reset, but as an internal Function, this hidden behavior is not very intuitive, and there are two problems:

  1. effectScope.on cannot handle nested recursive calls to itself, because the internal prevScope can only store one value.
  2. Not all situations that need to set currentInstance need to set instance.scope.on() at the same time, and this behavior is wrong in renderEffect.

So this PR removes instance.scope.on() in setCurrentInstance.

I initially started investigating this issue because of the following bug.

Bug Playground

In this example, try entering text.

There won't be any problem if just adding texts, once the the pe-existing texts get deleted, it will cause the call tosetText to fail.
This is because when the v-for element get unmounted, the effect.onStop() that does not belong to the v-for element would be mistakenly called. This is caused by the combined problems with problem "1" and "2" mentioned above.

@LittleSound LittleSound requested a review from sxzz April 5, 2024 13:21
Copy link

netlify bot commented Apr 5, 2024

Deploy Preview for vapor-repl ready!

Name Link
🔨 Latest commit 5a599d6
🔍 Latest deploy log https://app.netlify.com/sites/vapor-repl/deploys/661e03a82133610008f52594
😎 Deploy Preview https://deploy-preview-174--vapor-repl.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Apr 5, 2024

Deploy Preview for vapor-template-explorer ready!

Name Link
🔨 Latest commit 5a599d6
🔍 Latest deploy log https://app.netlify.com/sites/vapor-template-explorer/deploys/661e03a80901860008563d18
😎 Deploy Preview https://deploy-preview-174--vapor-template-explorer.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

github-actions bot commented Apr 5, 2024

Size Report

Bundles

File Size Gzip Brotli
compiler-dom.global.prod.js 80 kB 28.1 kB 24.7 kB
compiler-vapor.global.prod.js 49.5 kB 16.9 kB 15.3 kB
runtime-dom.global.prod.js 94.5 kB 35.6 kB 32 kB
runtime-vapor.global.prod.js 42.9 kB (+91 B) 15.9 kB (+25 B) 14.6 kB (+19 B)
vue-vapor.global.prod.js 89.8 kB (+92 B) 31.4 kB (+31 B) 28.3 kB (+1 B)
vue.global.prod.js 152 kB 54.9 kB 49 kB

Usages

Name Size Gzip Brotli
createApp 54.8 kB 21 kB 19.2 kB
createSSRApp 58.1 kB 22.3 kB 20.4 kB
defineCustomElement 57.1 kB 21.8 kB 19.9 kB
vapor 43.1 kB (+91 B) 16 kB (+20 B) 14.6 kB (+22 B)
overall 68.5 kB 26.1 kB 23.6 kB

Copy link
Member

@sxzz sxzz left a comment

Choose a reason for hiding this comment

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

LGTM. But could you please add unit tests for it?

@LittleSound
Copy link
Member Author

Added unit tests to the critical path that triggered the bug.

@LittleSound LittleSound force-pushed the fix/wrongly-assigned-effect-scope branch from b6bde54 to 5a599d6 Compare April 16, 2024 04:50
@sxzz sxzz merged commit b447ace into main Apr 16, 2024
@sxzz sxzz changed the title fix: wrongly assigned effect scope fix(runtime-vapor): detach effect scope & component instance Apr 16, 2024
@sxzz sxzz deleted the fix/wrongly-assigned-effect-scope branch April 16, 2024 08:55
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.

2 participants