Skip to content

Improve Acuant Global Code Comment#10247

Merged
night-jellyfish merged 5 commits intomainfrom
charley/improve-acuant-global-code-comment
Mar 15, 2024
Merged

Improve Acuant Global Code Comment#10247
night-jellyfish merged 5 commits intomainfrom
charley/improve-acuant-global-code-comment

Conversation

@charleyf
Copy link
Contributor

🎫 Ticket

This work happened because of this Slack thread.

🛠 Summary of changes

This PR updates a comment to be clearer.

Copy link
Contributor

@night-jellyfish night-jellyfish left a comment

Choose a reason for hiding this comment

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

Thank you for updating this!

* Global declarations
*/
declare let AcuantJavascriptWebSdk: AcuantJavascriptWebSdkInterface; // As of 11.7.0, this is now a global object that is not on the window object.
// As of 11.7.0, Acuant provides global objects that are not on the window object. We (identity-idp)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused by this, since I equate "window" and "global" in the context of a browser. How are they different? Or is this something in a worker?

In a web browser, any code [...] has a Window as its global object.

https://developer.mozilla.org/en-US/docs/Glossary/Global_object

Copy link
Contributor Author

@charleyf charleyf Mar 14, 2024

Choose a reason for hiding this comment

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

This is a good point. I do know that Acuant uses workers, but frankly didn't think too hard about this. I was/am leaning on the writeup here pretty heavily. Specifically:

In 11.7.0, this is no longer the case -- these objects are injected into the browser's global scope, but not added to the window object. This introduced three breaking difficulties: where to "find" the correct resources; the assumptions of our frontend test suite; and the assumptions of our type annotations.

I just added ( commit ) a link to that in the comment, since that's really the information a future reader needs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it at all possibly linked to the shadow DOM? Maybe the shadow DOM's global is not the window?

It sounds like from the documentation that window === global. But the history and comments in our code says otherwise. I don't feel I understand this level of how it all works (though I'd like to learn).

Copy link
Contributor

@aduth aduth Mar 14, 2024

Choose a reason for hiding this comment

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

It's quite possible we were just mistaken in some of that older code?

What happens if this line of code is removed altogether?

Copy link
Contributor

Choose a reason for hiding this comment

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

I removed it and a couple other lines complained about it missing. I updated them the best I could guess and it...seems fine? I do think there are still some problematic comments / code like here and here and probably others. Made a ticket for that: LG-12726.

But I think fixing them would be a bigger lift than this work was originally meant to be, and should probably be ticketed and prioritized, as changing it offhand could break the SDK.

@charleyf charleyf changed the title Charley/improve acuant global code comment Improve Acuant Global Code Comment Mar 14, 2024
@night-jellyfish
Copy link
Contributor

Charley and I agreed I'd take this work on - but I can't seem to remove my approval.

I think since I'm taking it on and I made a fairly big modification, it would be good if someone other than me could test / review.

Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Comment on lines 185 to 186
// eslint-disable-next-line no-console
console.error('AcuantJavascriptWebSdk is not defined in the global scope');
Copy link
Contributor

Choose a reason for hiding this comment

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

Not in scope of what you'd aimed to tackle, but I wonder why we log a message here. If we wanted to log something for us to be aware of, I'd think we'd use trackError. Or if it's for tests (to trip the browser log detection), I'd think we could wrap that in process.env.NODE_ENV. If it's for local development, I wouldn't think we should have it part of the committed code.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good point. I'm not sure what the original intent of this was either, tbh. It was added almost 2 years ago and I don't see a direct reference to the "why" for the console error.

I think reading through it, my take on it would be that we'd want to know if it's happening in production. The user would probably be encountering some kind of error already if there is no window.AcuantJavascriptWebSdk. And I think we'd want to know if that's happening to users (especially if it's happening to many).

So I think TrackError makes sense. (TIL trackError exists! I thought we always used trackEvent). I created LG-12733 to track that work. I found we use it twice in this file as well.

@night-jellyfish night-jellyfish merged commit 7f3a0a3 into main Mar 15, 2024
@night-jellyfish night-jellyfish deleted the charley/improve-acuant-global-code-comment branch March 15, 2024 19:44
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.

3 participants