Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions FEATURE-URL-DIAGRAM-ID.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Diagram ID in URL Feature + Multi-Tab Support

## Overview
This feature includes two major improvements:

### 1. Diagram ID in URL
Displays the current diagram ID in the URL, making it easier for users to:
- Share direct links to specific diagrams
- Bookmark specific diagrams
- See which diagram they are currently viewing
- Navigate back to specific diagrams using browser history

### 2. Multi-Tab Support
Removes the previous limitation that prevented opening the app in multiple browser tabs:
- Users can now work with multiple diagrams simultaneously across different tabs
- Graceful fallback from Firestore persistence when multiple tabs are detected
- No more blocking error messages when opening additional tabs

## Implementation Details

### URL Feature Changes
1. **`updateUrlWithDiagramId(diagramId)` method**: Updates the browser URL with the diagram ID using `window.history.replaceState()`
2. **Modified `setCurrentItem(item)` method**: Automatically updates URL when a diagram is loaded/switched
3. **Modified `createNewItem()` method**: Ensures new items get unique IDs before setting them as current
4. **Modified `forkItem(sourceItem)` method**: Generates new IDs for forked diagrams
5. **Enhanced lastCode handling**: Ensures restored items from localStorage have IDs

### Multi-Tab Support Changes
1. **Modified `getDb()` function in `src/db.js`**: Graceful fallback when Firestore persistence fails
2. **Removed blocking alert**: No more error message preventing multi-tab usage
3. **Persistence behavior**: First tab gets persistence, additional tabs work without persistence
4. **Error tracking**: Changed from `multiTabError` to `multiTabFallback` for analytics

### URL Format
- **With diagram**: `https://app.zenuml.com/?id=<diagram-id>`
- **Without diagram**: `https://app.zenuml.com/` (ID parameter removed)

### Behavior
- **New diagrams**: URL automatically updates with new random ID
- **Existing diagrams**: URL updates when diagram is opened/loaded
- **Forked diagrams**: URL updates with new forked diagram ID
- **Shared diagrams**: URL includes the shared diagram ID
- **Desktop app**: URL updates are skipped (no browser context)

## Testing

### Manual Testing
1. Open http://localhost:3000
2. Create a new diagram β†’ URL should show `?id=<new-id>`
3. Open an existing diagram β†’ URL should update to show that diagram's ID
4. Fork a diagram β†’ URL should show new forked diagram's ID
5. Refresh page with `?id=<existing-id>` β†’ Should load that specific diagram

### Automated Testing
Run the test script in browser console:
```javascript
// Load the test script and run
testUrlFunctionality();
```

## Benefits
- **Shareable links**: Users can copy URL to share specific diagrams
- **Bookmarking**: Users can bookmark specific diagrams
- **Navigation**: Browser back/forward works with diagram contexts
- **User experience**: Clear indication of which diagram is currently active

## Technical Notes
- Uses `replaceState` instead of `pushState` to avoid cluttering browser history
- Skips URL updates in desktop app environment
- Maintains backward compatibility with existing URL parameter handling
- Generates unique IDs for all new diagrams to ensure URL uniqueness

## Files Modified
- `src/components/app.jsx`: Core implementation of URL updating logic
- `src/db.js`: Multi-tab support and graceful Firestore persistence fallback
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"@radix-ui/react-radio-group": "^1.1.3",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-tooltip": "^1.0.7",
"@zenuml/core": "^3.35.1",
"@zenuml/core": "^3.40.1",
"clsx": "^2.0.0",
"code-blast-codemirror": "chinchang/code-blast-codemirror#web-maker",
"codemirror": "^5.65.16",
Expand Down
84 changes: 52 additions & 32 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading