Ensure that widget IDs can be reused. #2320
Merged
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.
Reworks the widget registry so that widget IDs can be re-used.
Instead of maintaining both an app-level and window-level registry, a single registry is maintained on the app, with widgets being added or removed as a result of assigning a the widget to the window. The window-level registry is then a filtered proxy over the main app registry. This avoids the problem reported as #2190 where the WeakRefDict at the App level wouldn't be cleared until a widget was garbage collected. Since there is no step where a widget is explicitly removed from the app, there is essentially no trigger (other than garbage collection) that could be used to purge from the app registry.
This means that a widget is not available for ID lookup until it has been assigned to a window as content. This is a backwards incompatible change, but one that aligns ID-based lookup with the DOM
getElementByID()
method.The implementation involves some minor changes to the order in which window and app are modified:
These shouldn't affect anything in normal operation, as assigning window and app shouldn't generally be something the end-user is doing.
Fixes #2190.
PR Checklist: