nasa-gcn / remix-seo

Collection of SEO utilities like sitemap, robots.txt, etc. for a Remix application. Forked from https://github.com/balavishnuvj/remix-seo
Other
77 stars 6 forks source link

Can't use server-side code to get sitemap entries #17

Open nichtsam opened 2 months ago

nichtsam commented 2 months ago

Describe the bug

Regarding the third example in this section: https://github.com/nasa-gcn/remix-seo?tab=readme-ov-file#configuration

handle is used by useMatches which ends up in client-side. https://remix.run/docs/en/main/route/handle

That leads to this error: Server-only module referenced by client.

Your Example Website or App

None

Steps to Reproduce the Bug or Issue

use any server-side code in getSitemapEntries in handle

Expected behavior

being able to generate sitemap entries with server-side code.

Screenshots or Videos

No response

Platform

Additional context

No response

platon-ivanov commented 1 month ago

I have the same issue.

For now handling it with vite-env-only works well.

import { serverOnly$ } from "vite-env-only";

export const handle: SEOHandle = {
    getSitemapEntries: serverOnly$(async (request) => {
        // your logic
    }),
};