UNPKG

alinea

Version:

[![npm](https://img.shields.io/npm/v/alinea.svg)](https://npmjs.org/package/alinea) [![install size](https://packagephobia.com/badge?p=alinea)](https://packagephobia.com/result?p=alinea)

38 lines (36 loc) 1.24 kB
"use client"; import "../../chunks/chunk-U5RRZUYZ.js"; // src/core/driver/NextPreviews.tsx import { chunkCookieValue } from "alinea/preview/ChunkCookieValue"; import { PREVIEW_ENTRYID_NAME, PREVIEW_PHASE_NAME, PREVIEW_UPDATE_NAME } from "alinea/preview/PreviewConstants"; import { usePreview } from "alinea/preview/react"; import { useRouter } from "next/navigation"; var MAX_CHUNKS = 5; function NextPreviews() { const router = useRouter(); const { isPreviewing } = usePreview({ async preview({ entryId, phase, update }) { const chunks = chunkCookieValue(PREVIEW_UPDATE_NAME, update); if (chunks.length > MAX_CHUNKS) { console.warn("Too many chunks, previewing will be disabled"); return; } const now = Date.now(); const expiry = new Date(now + 1e4); document.cookie = `${PREVIEW_ENTRYID_NAME}=${entryId};expires=${expiry.toUTCString()};path=/`; document.cookie = `${PREVIEW_PHASE_NAME}=${phase};expires=${expiry.toUTCString()};path=/`; for (const { name, value } of chunks) { document.cookie = `${name}=${value};expires=${expiry.toUTCString()};path=/`; } router.refresh(); } }); return null; } export { NextPreviews as default };