File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ node_modules/
55! website /public /hmze-logo.png
66! docs /workflow-diagram.svg
77.playwright-mcp /
8+ .venv /
9+ .linkedin /
810* :Zone.Identifier
911website /public /CONTRIBUTING.html
1012website /public /CONTRIBUTING.de.html
Original file line number Diff line number Diff line change @@ -356,10 +356,10 @@ export async function loadAnchorContent(anchorId) {
356356}
357357
358358export function showAnchorDetails ( anchorId ) {
359- const modal = document . getElementById ( 'anchor-modal' )
360- if ( modal ) {
361- modal . dataset . currentAnchor = anchorId
362- }
359+ // Share-link race: handleRoute may invoke us before initApp's createModal( )
360+ // microtask runs. createModal is idempotent.
361+ const modal = document . getElementById ( 'anchor-modal' ) || createModal ( )
362+ modal . dataset . currentAnchor = anchorId
363363 openModal ( )
364364 return loadAnchorContent ( anchorId )
365365}
Original file line number Diff line number Diff line change @@ -155,6 +155,22 @@ describe('anchor-modal', () => {
155155 const content = document . getElementById ( 'modal-content' )
156156 expect ( content . innerHTML ) . toContain ( 'Failed to load' )
157157 } )
158+
159+ it ( 'should not crash when modal element is missing (share-link race, #470)' , async ( ) => {
160+ const existing = document . getElementById ( 'anchor-modal' )
161+ if ( existing ) existing . remove ( )
162+
163+ global . fetch . mockResolvedValue ( {
164+ ok : true ,
165+ text : async ( ) => '= Test Anchor\n\nTest content' ,
166+ } )
167+
168+ await expect ( showAnchorDetails ( 'test-anchor' ) ) . resolves . not . toThrow ( )
169+
170+ const modal = document . getElementById ( 'anchor-modal' )
171+ expect ( modal ) . not . toBeNull ( )
172+ expect ( modal . classList . contains ( 'hidden' ) ) . toBe ( false )
173+ } )
158174 } )
159175
160176 describe ( 'umbrella anchors' , ( ) => {
You can’t perform that action at this time.
0 commit comments