feat: Add developer tools for ID discovery#23
Conversation
* Added a global (window-level) function that, when called, enables a "developer mode" in which all overridable elements show a small tag with their ID when hovered on. This helps simplify ID discovery by removing the need for manually searching through a potentially large codebase. * This change ensures that the DOM is completely unaffected when dev mode is not enabled, avoiding a major/breaking change to the library. * It also avoids a full re-render of the child element when dev mode gets enabled, which otherwise may cause errors with older components that have complex side effects and are not built to handle immediate unmount-remount cycles. * This currently has two limitations: 1. Some areas on the page with lots of densely nested overridables may cause overlapping ID tags to be rendered which is hard to read 2. Due to the absolute top-level rendering of the ID tags they are not pointer-interactive and their text can't be selected or copied. The developer has to manually type the ID into their IDE.
* Added documentation to reflect new feature added in indico/react-overridable#23
|
Looks great! Quick question: I did not fully understand this part
It looks like that you are showing them on hover/mousemove, or am I wrong? |
We are showing/hiding based on hover over the parent element of the overridable one. This is because we place a As such, we don't know exactly which overridable the user is hovering over, just the common parent of multiple elements. If we implemented a copy-to-clipboard feature for example, we wouldn't know exactly which ID to copy. Also, wrapping the component with a border would be somewhat difficult too, as this would potentially require some sort of container to wrap it (e.g. a div), meaning a full re-render is required when dev mode is activated, causing the errors I mentioned before. |
|
Do you have a dev instance where your PR is running right now (if it's just accessible from inside CERN that's fine)? I'd just like to try it out w/o the hassle of updating it on my local Indico instance. |
Not at the moment but I'm happy to set one up today |
* Removed the hover feature so that overridable ID tags are permanently shown while in dev mode instead. * Added a simple positioning algorithm to avoid overlaps between tags. This can mean the original nesting ordering is not preserved (i.e. a deeper nested overridable is not necessarily shown after a shallower one). But this way they are at least all evenly spaced and clearly visible * Added a function to copy the ID to clipboard when clicking on an ID tag
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
tomasr8
left a comment
There was a problem hiding this comment.
LGTM, I just had this last suggestion #23 (comment) which could make it a bit faster but it's not necessary
Apologies, I didn't notice your comment! I'll work on this now :) |
* Added documentation to reflect new feature added in indico/react-overridable#23
Closes #22
Part of inveniosoftware/invenio-app-rdm#3100
Added a global (window-level) function
reactOverridableDevModethat, when called, enables a "developer mode" in which all overridable elements show a small tag with their ID. This helps simplify ID discovery by removing the need for manually searching through a potentially large codebase.Kooha-2025-07-25-13-26-15.webm
This change ensures that the DOM is completely unaffected when dev mode is not enabled, avoiding a major/breaking change to the library.
<div>withposition: relativeand then showing aposition: absoluteID tag when hovered would significantly reduce the complexity of my implementation, but this has the risk of breaking designs that e.g. apply a fixed amount of margin between each child in a list, or overridables within HTML tables.It also avoids a full re-render of the child element when dev mode gets enabled, which otherwise may cause errors with older components that are not built to handle immediate unmount-remount cycles.
A small algorithm ensures that the ID tags do not overlap (or at least they don't overlap too much) but the nested ordering might not be preserved. For example, a deeper nested overridable in the same location might be shown higher up than a shallower one. The placing of tightly clustered ID tags is somewhat random and depends on the internal order of execution within React.
The ID tags can be clicked to copy their content to the clipboard
Kooha-2025-07-25-13-30-29.webm
This currently has two limitations:These limitations have now been fixed.Some areas on the page with lots of densely nested overridables may cause overlapping ID tags to be rendered which is hard to readSee example
Due to the absolute top-level rendering of the ID tags they are not pointer-interactive and their text can't be selected or copied. The developer has to manually type the ID into their IDE.For now I have used inline style objects where needed instead of CSS, to avoid adding a PostCSS step to rollup which might add too much complexity. However, I'm happy to change this if we think it will look neater.
I have thoroughly tested this on InvenioRDM. Also confirmed to be working on Indico:
Kooha-2025-07-24-10-29-41.webm