Skip to content

Commit d364e45

Browse files
authored
Merge pull request #474 from raifdmueller/fix/share-link-modal-race-470
fix: share-link first visit doesn't open anchor modal (#470)
2 parents 5e35499 + e8f7d67 commit d364e45

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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
911
website/public/CONTRIBUTING.html
1012
website/public/CONTRIBUTING.de.html

website/src/components/anchor-modal.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,10 @@ export async function loadAnchorContent(anchorId) {
356356
}
357357

358358
export 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
}

website/src/components/anchor-modal.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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', () => {

0 commit comments

Comments
 (0)