mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-08 22:48:14 -05:00
Fixed hydration error
This commit is contained in:
@@ -14,22 +14,6 @@ export default function RootLayout({
|
||||
}) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `window.INITIAL_TIMESTAMP = 0;`,
|
||||
}}
|
||||
/>
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
window.INITIAL_TIMESTAMP = Date.now();
|
||||
});
|
||||
`,
|
||||
}}
|
||||
/>
|
||||
</head>
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
)
|
||||
|
||||
@@ -31,6 +31,12 @@ export function ControlBar() {
|
||||
const { workflows, removeWorkflow, activeWorkflowId } = useWorkflowRegistry()
|
||||
const router = useRouter()
|
||||
|
||||
// Use client-side only rendering for the timestamp
|
||||
const [mounted, setMounted] = useState(false)
|
||||
useEffect(() => {
|
||||
setMounted(true)
|
||||
}, [])
|
||||
|
||||
// Get notifications for current workflow
|
||||
const workflowNotifications = activeWorkflowId
|
||||
? getWorkflowNotifications(activeWorkflowId)
|
||||
@@ -64,10 +70,14 @@ export function ControlBar() {
|
||||
<h2 className="font-semibold text-sm">
|
||||
{activeWorkflowId ? workflows[activeWorkflowId].name : 'Workflow'}
|
||||
</h2>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Saved{' '}
|
||||
{formatDistanceToNow(history.present.timestamp, { addSuffix: true })}
|
||||
</p>
|
||||
{mounted && ( // Only render the timestamp after client-side hydration
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Saved{' '}
|
||||
{formatDistanceToNow(history.present.timestamp, {
|
||||
addSuffix: true,
|
||||
})}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Middle Section - Reserved for future use */}
|
||||
|
||||
@@ -3,11 +3,4 @@ import { twMerge } from "tailwind-merge"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
|
||||
export const getTimestamp = () => {
|
||||
if (typeof window === 'undefined') {
|
||||
return Date.now()
|
||||
}
|
||||
return window.INITIAL_TIMESTAMP || Date.now()
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { create } from 'zustand'
|
||||
import { devtools } from 'zustand/middleware'
|
||||
import { NotificationType, Notification, NotificationStore } from './types'
|
||||
import { getTimestamp } from '@/lib/utils'
|
||||
|
||||
const STORAGE_KEY = 'workflow-notifications'
|
||||
|
||||
@@ -24,14 +23,18 @@ export const useNotificationStore = create<NotificationStore>()(
|
||||
notifications: loadPersistedNotifications(),
|
||||
|
||||
addNotification: (type, message, workflowId) => {
|
||||
// Only create notifications on the client side
|
||||
if (typeof window === 'undefined') return
|
||||
|
||||
const notification: Notification = {
|
||||
id: typeof window === 'undefined' ? '1' : crypto.randomUUID(),
|
||||
id: crypto.randomUUID(),
|
||||
type,
|
||||
message,
|
||||
timestamp: getTimestamp(),
|
||||
timestamp: Date.now(), // Simplified timestamp handling
|
||||
isVisible: true,
|
||||
workflowId
|
||||
}
|
||||
|
||||
set((state) => {
|
||||
const newNotifications = [...state.notifications, notification]
|
||||
persistNotifications(newNotifications)
|
||||
|
||||
Reference in New Issue
Block a user