JSConf EU is the annual European JavaScript conference covering browser APIs, framework internals, and web platform development. The 2025 edition dedicated several sessions to identifier design for modern web applications — covering the Web Crypto API, the gap between crypto.randomUUID() (v4 only) and the need for UUID v7 in the browser, optimistic UI patterns using client-generated IDs, and how React Server Components change where UUID generation should happen. This page covers the key technical points from those sessions.

The Web Crypto API and UUID v4

The browser’s crypto.randomUUID() method generates RFC 9562-compliant UUID v4:

// Available globally in all modern browsers (Chrome 92+, Firefox 95+, Safari 15.4+)
const id = crypto.randomUUID();
// "a8098c1a-f86e-11da-bd1a-00112444be1e"

MDN documents crypto.randomUUID() as backed by the OS CSPRNG — the same entropy source as crypto.getRandomValues(). It is the correct choice for client-side v4 generation. For UUID v7, import the uuid npm package:

import { v7 as uuidv7 } from 'uuid';
const id = uuidv7();
// "019236a7-b4f2-7000-8d3e-9c1a2b3d4e5f"

Optimistic UI with client-generated UUID v7

Optimistic UI patterns require the client to assign an ID before the server confirms the record. UUID v7 from the client gives a time-ordered ID that matches what the server would have generated:

import { v7 as uuidv7 } from 'uuid';

function OrderForm() {
  async function handleSubmit(formData) {
    const optimisticId = uuidv7(); // Client-assigned UUID v7

    // 1. Immediately update local UI state
    setOrders(prev => [...prev, {
      id: optimisticId,
      status: 'pending',
      ...formData
    }]);

    // 2. Send to server with the client-generated ID
    const res = await fetch('/api/orders', {
      method: 'POST',
      body: JSON.stringify({ id: optimisticId, ...formData }),
    });

    if (!res.ok) {
      // Rollback on failure
      setOrders(prev => prev.filter(o => o.id !== optimisticId));
    }
  }
}

The server must validate the UUID format before inserting — see the OWASP guidance below.

Server-side UUID validation for client-supplied IDs

Never trust client-supplied IDs without validation:

// Express / Next.js API route
import { validate, version } from 'uuid';

export async function POST(req) {
  const { id, ...data } = await req.json();

  // Validate UUID format and version
  if (!validate(id)) {
    return Response.json({ error: 'Invalid UUID format' }, { status: 400 });
  }
  if (version(id) !== 7) {
    return Response.json({ error: 'Expected UUID v7' }, { status: 400 });
  }

  // Check for ID collision before insert
  const existing = await db.orders.findById(id);
  if (existing) {
    return Response.json({ error: 'Duplicate ID' }, { status: 409 });
  }

  const order = await db.orders.create({ id, ...data });
  return Response.json(order, { status: 201 });
}

The OWASP Top 10 A01 Broken Access Control covers insecure direct object references — validating client-supplied IDs prevents ID injection attacks.

React Server Components and UUID generation

In Next.js App Router, server components run on the server where Date.now() is reliable and cryptographic entropy is always available:

// app/orders/page.tsx — Server Component
import { v7 as uuidv7 } from 'uuid';

export default async function OrdersPage() {
  // UUID generation in a Server Component — runs on server, no hydration issue
  const newOrderId = uuidv7();

  return <OrderForm defaultId={newOrderId} />;
}
// app/orders/OrderForm.tsx — Client Component
'use client';

export function OrderForm({ defaultId }: { defaultId: string }) {
  // ID provided by server — no UUID generation in client render
  const [id] = useState(defaultId);
  // ...
}

Generating the UUID in the server component and passing it as a prop avoids the hydration mismatch that occurs when uuidv7() is called during client-side rendering (different value on server and client). The React Server Components documentation explains the server/client boundary in detail.

Web Workers and UUID generation

For high-frequency UUID v7 generation (bulk data import, real-time event streams), offload to a Web Worker to avoid blocking the main thread:

// worker.js
import { v7 as uuidv7 } from 'uuid';

self.onmessage = ({ data: { count } }) => {
  const ids = Array.from({ length: count }, () => uuidv7());
  self.postMessage({ ids });
};

// main.js
const worker = new Worker('./worker.js', { type: 'module' });
worker.postMessage({ count: 10_000 });
worker.onmessage = ({ data: { ids } }) => {
  console.log(`Generated ${ids.length} UUID v7 values`);
};

The MDN Web Workers documentation covers module workers, message passing, and SharedArrayBuffer for zero-copy ID transfer.

Further reading

External references

Frequently asked questions

Can I generate UUID v7 in the browser without a library?

The browser's built-in crypto.randomUUID() only generates UUID v4. For UUID v7 in the browser you need a library — the uuid npm package bundles to ~2KB and provides v7(). It uses crypto.getRandomValues() for entropy and Date.now() for the timestamp, both available in all modern browsers. The Can I Use data for crypto.randomUUID() shows support from Chrome 92, Firefox 95, and Safari 15.4.

What are the risks of generating UUIDs client-side in a web application?

Client-generated UUIDs must be validated server-side before insertion — a client can send any string as an ID. Validate that the ID is a well-formed UUID and check for version and variant bits. UUID v4 IDs from clients should be re-validated using a library like validate() from the uuid npm package or a regex matching RFC 9562. The OWASP Top 10 covers insecure direct object references — never trust client-supplied IDs without server-side validation.

How does UUID v7 work with React Server Components?

In React Server Components (Next.js App Router), UUID generation runs on the server. Use the uuid package's v7() on the server to generate IDs before passing them to client components as props. Avoid generating UUIDs in the render function of client components — React may re-render and produce a different UUID, causing hydration mismatches. Generate IDs in event handlers or useEffect on the client side. The React Server Components documentation covers the server/client boundary.