Skip to content

feat(url): add project parameter for deep linking to specific sites(Done With AI as Assistant)#140

Open
ricardo-camilo-programador-frontend-web wants to merge 10 commits into
ihucos:masterfrom
ricardo-camilo-programador-frontend-web:feature/url-project-parameter
Open

feat(url): add project parameter for deep linking to specific sites(Done With AI as Assistant)#140
ricardo-camilo-programador-frontend-web wants to merge 10 commits into
ihucos:masterfrom
ricardo-camilo-programador-frontend-web:feature/url-project-parameter

Conversation

@ricardo-camilo-programador-frontend-web

@ricardo-camilo-programador-frontend-web ricardo-camilo-programador-frontend-web commented Jun 10, 2026

Copy link
Copy Markdown

Done With AI as Assistant

Problem

When users have multiple projects (websites) tracked by counter.dev and switch between them using the dropdown selector, the dashboard often fails to load the correct data for the selected project. The root cause is a lack of synchronization between the URL state and the internal dashboard state.

Current Behavior

  • Dashboard loads all projects via SSE (/dump)
  • First project in list (by visit count) is displayed, not the one user intended
  • When switching projects via <select>:
    • Frontend calls /setPrefSite?site=x
    • Backend updates Redis preference
    • Frontend reuses cached dump with different selector.site
    • Graphs/components display WRONG data (from previous site)
  • No URL state: refreshing page loses selected project

Solution

Add ?project=x parameter to dashboard URL to enable deep linking and state synchronization.

Backend Changes

File: backend/endpoints/dump.go

Read project query parameter and add to dump meta:

var user models.User
meta := map[string]string{}

// Read project parameter from URL
projectFromUrl := ctx.R.FormValue("project")
if projectFromUrl != "" {
    meta["project"] = projectFromUrl
}

Impact: +7 lines

Frontend Changes

File: static/components/dashboard/selector.js

  1. Read project parameter from backend meta response
  2. Use meta.project for initial site selection (priority over prefs.site)
  3. Update URL when switching projects via history.pushState()
  4. Handle browser back/forward via popstate events (skip pushState to avoid circular history)

Impact: +21 lines, -7 lines

File: static/js/dashboard.js

  • Changed var to const for immutable variables
  • Fixed typo: "very import element" → "very important element"

Impact: +4 lines, -4 lines


Benefits

  • Fix data loading bug when switching projects
  • Enable deep linking to specific projects
  • Allow bookmarking project views
  • Improve cross-device consistency (same URL = same view)
  • Maintain backward compatibility (URL param optional)
  • Enable sharing of project dashboards

Example URLs

/dashboard.html?user=CamillusBloodfallen&token=Q5ysSKM8YJI%3D&project=example.com
/dashboard.html?project=myportfolio.com

Code Review Status

Latest Review: #140 (comment)

All CRITICAL and MAJOR issues resolved:

✅ CRITICAL: Backend compilation error (meta used before declaration) — FIXED
✅ CRITICAL: Runtime TypeError (const reassignment in demo mode) — FIXED
✅ MAJOR: Circular history mutation in popstate — FIXED
✅ MAJOR: Unused variable this.projectFromUrlFIXED
✅ MAJOR: Event handler signature mismatch — FIXED
✅ MAJOR: Go style issues (fails gofmt) — PENDING


Testing

  • Multi-project switching
  • Direct URL access with ?project=x
  • Browser back/forward (no circular history)
  • Sessionless access (token-based)
  • No compilation errors (Go)
  • No runtime errors (demo mode)
  • No regression in existing flows (pending re-review)
  • Go formatting check (gofmt) — pending

Related

Closes #141

Done With AI as Assistant

- Backend: Read project parameter and add to dump meta
- Frontend: Use meta.project for initial selection, update URL on switch
- Add popstate handler for browser back/forward navigation
- Update Open Design document

Closes: Multi-project data loading bug when switching sites
@ricardocamiloconsir

This comment has been minimized.

@ricardocamiloconsir

This comment has been minimized.

@ricardocamiloconsir

This comment has been minimized.

@ricardocamiloconsir

This comment has been minimized.

ricardocamiloconsir

This comment was marked as outdated.

ricardocamiloconsir

This comment was marked as outdated.

ricardocamiloconsir

This comment was marked as outdated.

ricardocamiloconsir

This comment was marked as outdated.

- Convert SDD document to American English
- Convert SDD workflow to American English
- Remove Portuguese ROTINA_SDD.md
- Add rule: ALL GitHub content must be in American English
- Remove CODE_QUALITY_IMPROVEMENTS.md
- Remove SETUP.md
- Remove docs/OD_url-project-parameter.md
- Remove docs/SDD_WORKFLOW.md
- Remove docs/SDD_url-project-parameter.md

Keep only code changes for the feature implementation.
@ricardocamiloconsir

This comment has been minimized.

Backend (dump.go):
- Move project parameter reading AFTER meta declaration
- Fixes compilation error (meta used before declaration)
- Simplify comment (remove unnecessary parenthetical)

Frontend (selector.js):
- Remove dead code this.projectFromUrl (never read)
- Fix circular history mutation in popstate handler
- Add updateHistory parameter to onSiteSelChanged
- Skip pushState when triggered by popstate navigation
- Change const sites to let sites (reassigned in demo mode)

Resolves:
- CRITICAL: Go compilation error
- CRITICAL: Runtime TypeError (const reassignment in demo)
- MAJOR: Circular history mutation breaking back/forward
- MAJOR: Unused variable
- MAJOR: Event handler signature mismatch
@ricardo-camilo-programador-frontend-web

This comment was marked as outdated.

@ricardo-camilo-programador-frontend-web

This comment was marked as outdated.

@ricardo-camilo-programador-frontend-web

This comment was marked as outdated.

@ricardo-camilo-programador-frontend-web

Copy link
Copy Markdown
Author

✅ All critical issues from previous reviews have been resolved in commit a85a279:

  • Fixed Go compilation error (meta used before declaration)
  • Fixed runtime TypeError in demo mode (const → let)
  • Fixed circular history mutation (added updateHistory flag)
  • Removed unused variable this.projectFromUrl
  • Fixed event handler signature mismatch

PR is now ready for final review. The implementation is clean, focused, and addresses all blockers.

Note: The remaining items (Go formatting, input validation) are non-blocking enhancements that can be addressed in a future PR.

Thank you for the detailed review!

@ricardo-camilo-programador-frontend-web ricardo-camilo-programador-frontend-web changed the title feat(url): add project parameter for deep linking to specific sites feat(url): add project parameter for deep linking to specific sites(Done With IA as Assistante) Jun 16, 2026
@ricardo-camilo-programador-frontend-web

ricardo-camilo-programador-frontend-web commented Jun 16, 2026

Copy link
Copy Markdown
Author

Done With AI as Assistant

@ricardo-camilo-programador-frontend-web ricardo-camilo-programador-frontend-web changed the title feat(url): add project parameter for deep linking to specific sites(Done With IA as Assistante) feat(url): add project parameter for deep linking to specific sites(Done With AI as Assistant) Jun 16, 2026
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.

[Feature] URL parameter for deep linking to specific sites

2 participants