Developing locally with Next.js App Router SDK

Developer preview

This feature is in developer preview. Use with caution as it may change unexpectedly. For more information, contact us.

Developer Preview

This page documents the developer preview of the SDK, version 20.81.1-alpha.25.sha-f076f9b857.

This page tells you how the SDK behaves under next dev, and how to see your content changes fast.


When NODE_ENV is development, the resolvers of @uniformdev/next-app-router do not use the Next.js data cache. They get the route and the composition from Uniform on each request. Thus a page shows newly published content when you load it again. The 'use cache' resolvers of @uniformdev/next-app-router/cache are different: they keep published results also in development.

The Context manifest is different. UniformContext gets the published manifest with force-cache, also in development. If a new signal or test does not work locally, do a hard reload of the page in the browser. If that does not help, delete the .next folder:

rm -rf .next && npm run dev

note

next build and next start use the production behavior. Then the resolvers cache published content until a webhook revalidates it. Refer to Caching.


You do not have to publish content to see it locally. In Next.js draft mode, the SDK gets draft content and does not use the cache.

To enable draft mode, open your local app from the Uniform preview panel:

  1. Open a composition in Canvas.
  2. Open the preview panel.
  3. From the menu of the preview panel, select Open in new window.
open-new-tab
Open in a new window

The preview handler enables Next.js draft mode and opens the page. While draft mode is on:

  • The SDK gets draft content.
  • The resolvers do not use the cache.
  • The browser chooses the personalization and test variants. Edge mode does not apply to draft requests.

To turn off draft mode, open /api/preview?disable=true&path=/ in the same browser.

note

Set UNIFORM_PREVIEW_SECRET in .env.local. It must be the same as the secret in the preview URL of your Uniform project. If it is not set, the preview handler answers 401 No preview secret is configured.


The Vercel edge middleware works under next dev, without the Vercel runtime cache:

  • vercelManifestProvider gets the manifest from the Uniform API, and keeps a copy in memory.
  • vercelEdgeRouteStore keeps its records in memory.
  • expireVercelRuntimeCacheTags does nothing.

To use the Vercel runtime cache locally, set RUNTIME_CACHE_ENDPOINT.

Under next dev, Next.js shows deprecation warnings for middleware.ts and for the edge runtime. These warnings are expected. Refer to Keep middleware.ts on the edge runtime.


Edge personalization uses a published page from the cache, so do the test on a production build:

  1. Build and start the app:

    npm run build && npm run start
  2. Open a page that has a personalization, with a URL that activates a signal. For example, http://localhost:3000/?utm_campaign=launch for a signal that reads the utm_campaign query string.

  3. Look at the HTML of the response. It must contain only the personalized variant:

    curl -s "http://localhost:3000/?utm_campaign=launch" | grep -o '__UNIFORM_DATA__[^<]*'

    The __UNIFORM_DATA__ script contains the scores of the visitor.


ProblemSolution
A new signal or test does not work locallyDo a hard reload, or delete .next and start the dev server again
You want to see content before you publish itOpen the app from the Uniform preview panel (draft mode)
You want to see edge personalizationUse a production build: npm run build && npm run start