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
[Meteor 3] Environment Variable Tweaks #13128
Conversation
…fix resetting value too early
✅ Deploy Preview for v3-migration-docs canceled.
|
✅ Deploy Preview for v3-meteor-api-docs canceled.
|
function () { | ||
Meteor._updateAslStore(CURRENT_VALUE_KEY_NAME, value); | ||
Meteor._updateAslStore(UPPER_CALL_DYNAMICS_KEY_NAME, dynamics); | ||
return func(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will not work.
We need to wait for the func()
to finish and reset the states of CURRENT_VALUE_KEY_NAME
and UPPER_CALL_DYNAMICS_KEY_NAME
after the func()
is done.
This is because you can call a withValues
inside another, and you need to set and reset those states to keep context between calls.
Otherwise, you'll get issues like this: #13063
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#13063 changed it to create a new dynamics object each time instead of mutating the parent dynamics. This should remove the need to reset the state since the parent and children all have their own state. If you comment out the reset code, the example code from the PR description stills works correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @zodern, I will include that code as a test just to make sure.
packages/meteor/dynamics_browser.js
Outdated
|
||
if (isPromise) { | ||
var self = this; | ||
return ret.finally(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The meteor package could run in environments that have promises, but does not have Promise.finally. The promise
package would polyfill it, but apps aren't required to use it.
One interesting side effect of this is tests now run inside a method. Meteor 1/2 uses I'm wondering if there should be a new api to run a function in a fresh environment. Meteor 1/2 supported this by simply creating a new fiber and running code inside it, or using the api variants that do not preserve the environment (setTimeout instead of Meteor.setTimeout, setImmediate instead of Meteor.setImmediate, etc.). Meteor 3 doesn't have any public api's to do the same. |
This reverts commit e7d8d32.
The implementation looks good. It probably should wrap this code or some other pat of the queue to maintain the behavior in Meteor 1/2 of not preserving the environment when running the queued tasks and so tests don't run inside a method. |
Addresses these two issues:
#13112
#13113
withValue
indynamics_browser.js
so it behaves similar to the server when handling promises.meteor/packages/meteor/dynamics_browser.js
Line 49 in 08c2d7b