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

[Meteor 3] Environment Variable Tweaks #13128

Merged
merged 30 commits into from May 21, 2024

Conversation

leonardoventurini
Copy link
Member

@leonardoventurini leonardoventurini commented May 9, 2024

Addresses these two issues:

#13112
#13113

  1. No need to reset EV's value manually since ALS already handles it well by creating a new object every time.
  2. Make sure the function's return value is preserved, WITHOUT enforcing a promise in the server.
  3. Adjust the Client's withValue in dynamics_browser.js so it behaves similar to the server when handling promises.

@leonardoventurini leonardoventurini changed the base branch from devel to release-3.0 May 9, 2024 12:52
@github-actions github-actions bot temporarily deployed to pull request May 9, 2024 12:52 Inactive
@github-actions github-actions bot temporarily deployed to pull request May 9, 2024 12:52 Inactive
Copy link

netlify bot commented May 9, 2024

Deploy Preview for v3-migration-docs canceled.

Name Link
🔨 Latest commit e413a04
🔍 Latest deploy log https://app.netlify.com/sites/v3-migration-docs/deploys/664b9370a8a7fe00091498af

Copy link

netlify bot commented May 9, 2024

Deploy Preview for v3-meteor-api-docs canceled.

Name Link
🔨 Latest commit e413a04
🔍 Latest deploy log https://app.netlify.com/sites/v3-meteor-api-docs/deploys/664b93704d382700083810f4

@leonardoventurini leonardoventurini marked this pull request as draft May 9, 2024 13:54
function () {
Meteor._updateAslStore(CURRENT_VALUE_KEY_NAME, value);
Meteor._updateAslStore(UPPER_CALL_DYNAMICS_KEY_NAME, dynamics);
return func();
Copy link
Contributor

@denihs denihs May 10, 2024

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

Copy link
Member

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.

Copy link
Member Author

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 Show resolved Hide resolved

if (isPromise) {
var self = this;
return ret.finally(function () {
Copy link
Member

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.

@zodern
Copy link
Member

zodern commented May 10, 2024

One interesting side effect of this is tests now run inside a method.

Meteor 1/2 uses setImmediate to schedule running the tests, which does not preserve the environment. However, in Meteor 3 Async Local Storage does preserve the store value for the setImmediate callback.

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.

.envrc Show resolved Hide resolved
@leonardoventurini
Copy link
Member Author

@zodern This seems to work, what do you think?

a8edea4

52712ee

@leonardoventurini leonardoventurini marked this pull request as ready for review May 14, 2024 19:22
@zodern
Copy link
Member

zodern commented May 14, 2024

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.

denihs
denihs previously approved these changes May 15, 2024
@StorytellerCZ StorytellerCZ added this to the Release 3.0 milestone May 18, 2024
@leonardoventurini leonardoventurini merged commit 6f1623e into release-3.0 May 21, 2024
14 checks passed
@leonardoventurini leonardoventurini deleted the feature/ev-improvements branch May 21, 2024 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants