-
-
Notifications
You must be signed in to change notification settings - Fork 285
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
fix: Add workaround for OpenTelemetry/Zone.js #1719
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b73586f
fix: Follow-up for #1573 to also handle the case when a non-default l…
amannn b44c8ef
Merge branch 'main' into canary
amannn b4de1a0
Merge remote-tracking branch 'origin/main' into canary
amannn 84fe6d0
fix: Add workaround for OpenTelemetry/Zone.js (#1718)
amannn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
What do you think about adding an additional check of the well-known symbol
[Symbol.toStringTag]
prototype?Zone.js returns 'Promise', the same as the native Promise. https://github.com/angular/zone.js/blob/master/lib/common/promise.ts#L364
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.
You mean in addition to
then === 'function'
? Hmm, it's an interesting point, I honestly didn't know aboutSymbol.toStringTag
.Based on the MDN docs on
Symbol.toStringTag
it seems like this would be safe to use on promises. However, I'm a bit reluctant as I've already encountered a range of weird cases where Next.js' overrides internals, patched something here and there, and sometimes things go off the rails.Is there a specific use case where you think the current check might not work well?
As an additional note on the implementation, I put the focus on providing a minimal implementation that minifies as much as possible while being reliable. I took the
is-promise
implementation as inspiration and removed some checks that are not necessary for the waysisPromise
is currently used in this codebase.What do you think?
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.
Hi @amannn, first of all thanks for the quick support 😄, I tested locally with version
0.0.0-canary-84fe6d0
and it works as expected!as @SalmenBejaoui suggest, probably
Promise.prototype[Symbol.toStringTag] === 'Promise'
could be useful, at least it should also handle the native promise override case.about the
zonePromise[Symbol.toStringTag] === 'Promise'
could be a bit unsafe? it seems only zonejs related which isn't used on this library.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.
Sure, that's great to hear!
What I'm trying to understand is how the additional usage of
Symbol.toStringTag
is benefical? Is there a case where the current check forthen === 'function'
is not sufficient?Please also see:
My main motivation is to have something that minifies as much as possible. Additionally, for the way
isPromise
is used in this codebase we can take some shortcuts in comparison to theis-promise
package npm.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.
Oh ok, now with the
Promise spec
I got it, so yes, I thinkthen === 'function'
is sufficient to cover the promise case (I don't think that someone besides overwriting the global promise object, also edits the signature of the functions, hopefully...).looks good like this to me.
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.
@amannn the thenable check is sufficient and follows A+ spec.
Promise.prototype[Symbol.toStringTag]
could be too strict.I was thinking more widely, but it's not the case for next-intl.
LGTM 👍
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.
Got it, sounds good! Many thanks for your research on this and for providing feedback, I really appreciate it and I'm sure other Next.js users will benefit from this too!