Fix generating same ids when using different apps, e.g. in module federation#1917
Merged
Fix generating same ids when using different apps, e.g. in module federation#1917
Conversation
|
matyasf
commented
Mar 27, 2025
Comment on lines
+39
to
+46
| function generateInstanceCounterMap(): DeterministicIdProviderValue { | ||
| if (globalThis[__INSTUI_GLOBAL_INSTANCE_COUNTER__]) { | ||
| return globalThis[__INSTUI_GLOBAL_INSTANCE_COUNTER__] | ||
| } | ||
| const map = new Map<string, number>() | ||
| globalThis[__INSTUI_GLOBAL_INSTANCE_COUNTER__] = map | ||
| return map | ||
| } |
Collaborator
Author
There was a problem hiding this comment.
This is the main fix
matyasf
commented
Mar 27, 2025
| const { currentPageId, renderOptionContent } = options | ||
|
|
||
| const customPopoverIdMap = generateInstanceCounterMap() | ||
| const customPopoverIdMap = new Map<string, number>() |
Collaborator
Author
There was a problem hiding this comment.
using the global counter caused here a weird bug, I think because it was re-rendered multiple times the IDs got out of sync causing the menu buttons in SmallViewport mode to break.
matyasf
commented
Mar 27, 2025
balzss
reviewed
Mar 28, 2025
Contributor
balzss
left a comment
There was a problem hiding this comment.
I'm rewriting a lot of the regression test in this commit so you changes would be deleted (or updated) anyway, can you leave it out from this pr?
HerrTopi
approved these changes
Mar 31, 2025
| var __INSTUI_GLOBAL_INSTANCE_COUNTER__: Map<string, number> | ||
| } | ||
| const __INSTUI_GLOBAL_INSTANCE_COUNTER__ = '__INSTUI_GLOBAL_INSTANCE_COUNTER__' | ||
|
|
Contributor
There was a problem hiding this comment.
This name is the same as the above, global name on the globalThis. Works but could be more readable if you'd rename the const variable to something else
Collaborator
Author
There was a problem hiding this comment.
Good catch, I've renamed it
d05e0c4 to
7a5670d
Compare
…s of InstUI, e.g. module federation Its fixed by moving the instance counter to the global object. Also the generation pattern is altered slightly to work nicely with older versions of InstUI which do not use this new global object Fixes INSTUI-4484
7a5670d to
0eb8ff5
Compare
balzss
approved these changes
Mar 31, 2025
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The cause of this issue was that we generate IDs on the ESM module level, and if 2 or more InstUI applications are executed as a downloaded .js file (like in Module federation) the instance counters are not aware of each other and are generating the same IDs causing all kinds of issues, e.g. with Radio buttons.
To test: Check out https://github.com/matyasf/module-federation-instui and use this build as a dependency -- version
10.14.1-pr-snapshot-1743089682418