-
Notifications
You must be signed in to change notification settings - Fork 25.8k
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(core): prevent stash listener conflicts #59635
base: main
Are you sure you want to change the base?
Conversation
93414f0
to
20b19ab
Compare
const stashEventListener = stashEventListeners.get(appId)!; | ||
stashEventListener(native, eventName, listenerFn); |
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 non null assertion deviates from a prior safety net where an empty closure would be used, so the following seems safer and less of a change:
const stashEventListener = stashEventListeners.get(appId)!; | |
stashEventListener(native, eventName, listenerFn); | |
const stashEventListener = stashEventListeners.get(appId); | |
stashEventListener?.(native, eventName, listenerFn); |
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.
Updated to optional chaining.
20b19ab
to
7c91668
Compare
The stash event listener is a global function that might be unsafely overridden if multiple microfrontend applications exist on the page. In this commit, we create a map of `APP_ID` to stash event listener functions. This map prevents conflicts because multiple applications might be bootstrapped simultaneously on the client (one rendered on the server and one rendering only on the client). I.e., the code that might be used is: ```ts // Given that `app-root` is rendered on the server bootstrapApplication(AppComponent, appConfig); bootstrapApplication(BlogRootComponent, appBlogConfig); ``` Two bootstrapped applications would conflict and override each other's code.
7c91668
to
f29a5a8
Compare
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.
We'll definitely need some tests here for this so we don't regress in the future. Can you add those?
The stash event listener is a global function that might be unsafely overridden if multiple microfrontend applications exist on the page.
In this commit, we create a map of
APP_ID
to stash event listener functions. This map prevents conflicts because multiple applications might be bootstrapped simultaneously on the client (one rendered on the server and one rendering only on the client).I.e., the code that might be used is:
Two bootstrapped applications would conflict and override each other's code.