Skip to content
Merged
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
33 changes: 14 additions & 19 deletions apps/master-sample-app/app/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ export default function Page() {
return newDocId
}, [])

// Update URL when sample or documentId changes
useEffect(() => {
if (typeof window === 'undefined' || !documentId) return

const sample = getSampleById(currentSampleId)
if (!sample) return

const routePath = sample.metadata.routePath || ''
const newUrl = `${routePath}?documentId=${documentId}`

if (window.location.pathname + window.location.search !== newUrl) {
window.history.pushState({}, '', newUrl)
}
}, [currentSampleId, documentId])

// Initialize: determine sample from URL path and get/set document ID
useEffect(() => {
if (isInitialized.current) return
Expand Down Expand Up @@ -104,6 +89,16 @@ export default function Page() {
}
}, [])

// Handle sample selection: clear documentId first to prevent race condition

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL not updated with documentId on default sample load

The removed effect that ran on documentId change was responsible for updating the URL after initialization. The new sample change effect only runs when currentSampleId changes. When loading the root path with the default sample (where targetSampleId === currentSampleId), setCurrentSampleId is not called, so the sample change effect never runs and the URL is never updated with the documentId. This breaks the share/collaboration feature since users cannot copy a URL containing the document ID.

Additional Locations (1)

Fix in Cursor Fix in Web

// where iframe renders with new sample URL but old documentId
const handleSampleSelect = useCallback((newSampleId: string) => {
if (newSampleId === currentSampleId) return
// Clear documentId FIRST to ensure iframe doesn't render with mismatched sample/document
// This triggers "Loading demo..." state until the effect sets the correct documentId
setDocumentId('')
setCurrentSampleId(newSampleId)
}, [currentSampleId])

// Handle sample change: get document ID for the new demo
useEffect(() => {
if (!isInitialized.current) return
Expand All @@ -123,7 +118,7 @@ export default function Page() {
// Update URL
const routePath = sample.metadata.routePath || ''
const newUrl = `${routePath}?documentId=${docId}`

if (window.location.pathname + window.location.search !== newUrl) {
window.history.pushState({}, '', newUrl)
}
Expand Down Expand Up @@ -169,11 +164,11 @@ export default function Page() {
return (
<div className="flex h-screen overflow-hidden bg-background">
{/* Sidebar */}
<Sidebar
isOpen={sidebarOpen}
<Sidebar
isOpen={sidebarOpen}
onToggle={() => setSidebarOpen(!sidebarOpen)}
currentSampleId={currentSampleId}
onSampleSelect={setCurrentSampleId}
onSampleSelect={handleSampleSelect}
/>

{/* Main Content */}
Expand Down
Loading