fix: share-link first visit doesn't open anchor modal (#470)#474
Conversation
Both are local-only directories (Python virtualenv and LinkedIn skill cache) that shouldn't be tracked.
…M-Coding#470) When a user opens a share-link like /#/anchor/<slug> in a fresh tab, the router's handleRoute() called showAnchorDetails() before initApp's createModal() microtask had a chance to run. loadAnchorContent then crashed with "Cannot read properties of null (reading 'querySelector')", leaving the modal element missing and the homepage visible underneath. On a second visit the modal already existed in the DOM, so the bug appeared as "works on second click." Guard showAnchorDetails by calling the idempotent createModal() when the element is missing. Add a regression test that removes the modal element before calling showAnchorDetails and asserts the modal is created and opened. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughDas Pull Request behebt eine Racebedingung bei Anker-Freigabelinks, die beim ersten Besuch dazu führt, dass das Modal nicht geöffnet wird. Die Funktion ChangesBehebung der Racebedingung bei Anker-Modalen
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Closes #470
Summary
When opening a share-link like `/#/anchor/` in a fresh tab, the homepage was rendered instead of the anchor modal. On a second visit the modal already existed and the link worked — making the bug look intermittent.
Root cause
`router.handleRoute()` invoked `showAnchorDetails()` before `initApp`'s `createModal()` microtask ran. `loadAnchorContent()` then crashed inside the dynamic-import callback with:
```
TypeError: Cannot read properties of null (reading 'querySelector')
at loadAnchorContent (anchor-modal.js:164)
```
The modal element didn't exist yet, the URL got rewritten to `/anchor/...` by the SPA's hash→path migration, the title was set correctly, but no modal opened.
Fix
Guard `showAnchorDetails()` by calling the idempotent `createModal()` when the element is missing. Cheap, defensive, no behavioral change on the happy path.
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes