SvelteConf 2025 gathered the Svelte community for two days of talks in San Francisco. UUID v7 appeared in sessions on SvelteKit data patterns, form actions, and database integration — with speakers praising SvelteKit’s clean server/client boundary as a natural fit for safe UUID generation. See UUID in Svelte and SvelteKit for the full implementation guide.

Session: UUID v7 in SvelteKit form actions

// src/routes/orders/+page.server.ts
import type { Actions } from './$types';
import { v7 as uuidv7 } from 'uuid';
import { db } from '$lib/db';
import { orders } from '$lib/schema';

export const actions: Actions = {
  create: async ({ request }) => {
    const data = await request.formData();
    const order = {
      id: uuidv7(),  // server-only — no hydration risk
      customerId: data.get('customerId') as string,
      total: Number(data.get('total')),
    };

    await db.insert(orders).values(order);
    return { orderId: order.id };
  },
};
<!-- src/routes/orders/+page.svelte -->
<script lang="ts">
  import { enhance } from '$app/forms';
  export let form;
</script>

<form method="POST" action="?/create" use:enhance>
  <input name="customerId" required />
  <input name="total" type="number" required />
  <button>Create Order</button>
</form>

{#if form?.orderId}
  <p>Order created: {form.orderId}</p>
{/if}

The speaker emphasised that uuidv7() in a form action runs exclusively on the server — no $app/environment guard needed. See UUID Generation Strategies.

Session: Drizzle ORM + SvelteKit + UUID v7

// src/lib/schema.ts
import { pgTable, uuid, text, numeric } from 'drizzle-orm/pg-core';
import { sql } from 'drizzle-orm';

export const orders = pgTable('orders', {
  id:       uuid('id').primaryKey().default(sql`uuidv7()`),
  customer: text('customer').notNull(),
  total:    numeric('total').notNull(),
});
// src/lib/db.ts
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';

const client = postgres(process.env.DATABASE_URL!);
export const db = drizzle(client);

See UUID in Drizzle ORM for the migration setup.

Session: UUID v7 in SvelteKit hooks for trace IDs

// src/hooks.server.ts
import { v7 as uuidv7 } from 'uuid';
import type { Handle } from '@sveltejs/kit';

export const handle: Handle = async ({ event, resolve }) => {
  // Assign UUID v7 trace ID to each request
  const traceId = event.request.headers.get('x-trace-id') ?? uuidv7();
  event.locals.traceId = traceId;

  const response = await resolve(event);

  // Echo back as response header
  response.headers.set('x-trace-id', traceId);
  return response;
};
// src/app.d.ts — type the traceId in locals
declare global {
  namespace App {
    interface Locals {
      traceId: string;
    }
  }
}

UUID v7 trace IDs in SvelteKit hooks are available in all load functions and actions via event.locals.traceId. See UUID v7 in Microservices — trace IDs.

Session: Cursor pagination in SvelteKit loaders

// src/routes/orders/+page.server.ts
import type { PageServerLoad } from './$types';
import { db } from '$lib/db';
import { orders } from '$lib/schema';
import { gt } from 'drizzle-orm';

export const load: PageServerLoad = async ({ url }) => {
  const cursor = url.searchParams.get('cursor') ?? undefined;
  const limit = 20;

  const rows = await db
    .select()
    .from(orders)
    .where(cursor ? gt(orders.id, cursor) : undefined)
    .orderBy(orders.id)
    .limit(limit);

  return {
    orders: rows,
    nextCursor: rows.length === limit ? rows[rows.length - 1].id : null,
  };
};

See UUID v7 for Cursor Pagination.

Further reading

External references

Frequently asked questions

How is UUID v7 generated safely in SvelteKit?

SvelteKit form actions and API routes (+server.ts files) run exclusively on the server. Importing the uuid npm package and calling v7() in an action or +server.ts file is safe — SvelteKit will not include these imports in the client bundle when they are used only in server-side code. See UUID in Svelte and SvelteKit.

Can I store UUID v7 IDs in a Svelte store?

Yes, but generate them on the server first. In a SvelteKit form action, generate the UUID v7, insert to the database, then return the ID for the client to store. Never call v7() in a Svelte store initialiser that runs during hydration — this produces a different UUID on client and server, causing a mismatch.