Skip to content

Conversation

Copy link

Copilot AI commented May 23, 2025

Problem

The refs dictionary in window.__keyborg was not using a shared ID system, leading to potential ID conflicts when multiple bundles of the library are loaded on the same page. This could cause reference management issues where one bundle might overwrite or conflict with references created by another bundle.

Solution

This PR implements a shared ID system by:

  1. Adding a lastId property to the WindowWithKeyborg interface to track the last used ID
  2. Modifying the Keyborg constructor to:
    • Initialize lastId if it doesn't exist in the window object
    • Ensure the refs dictionary is properly initialized
    • Use the shared lastId from window.__keyborg when creating new instances
  3. Updating the KeyborgCore constructor to also use the shared lastId

Testing

The code has been thoroughly tested to ensure:

  • Backward compatibility with unfixed bundles
  • Proper initialization of the refs dictionary
  • Correct ID generation across multiple bundle instances

Implementation Details

The implementation maintains backward compatibility by checking if properties exist before using them, and initializing them with appropriate values if they don't exist.

Before this fix, each bundle maintained its own ID counter (_lastId). Now, all bundles share a global ID counter stored in window.__keyborg.lastId, ensuring consistent and unique IDs across all bundles.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: mathis-m <11584315+mathis-m@users.noreply.github.com>
Copilot AI changed the title [WIP] Update Keyborg refs dictionary to use shared ID Implement shared ID in window.__keyborg for refs dictionary May 23, 2025
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.

1 participant