sanity-io / language-filter

A Sanity plugin that supports filtering localized fields by language
MIT License
17 stars 1 forks source link

"The page tool crashed" #59

Open tutkun opened 8 months ago

tutkun commented 8 months ago

Error: "The page tool crashed"

I'm using Next.js 14.0.3 App Router and Sanity.io v3. I'm getting the error shown in the image below. I'm connecting to Sanity.io using the "next-sanity" package in Nextjs. I think there is a problem with the "language-filter" of next-sanity. Can you help me please?

Screenshots:

Ekran Resmi 2023-11-28 11 07 14

These are sanity versions:

@sanity/cli (global)                   3.20.1 (up to date)
@sanity/cli                            3.20.1 (up to date)
@sanity/color                           2.2.5 (up to date)
@sanity/dashboard                       3.1.5 (up to date)
@sanity/document-internationalization   2.0.2 (up to date)
@sanity/icons                           2.7.0 (up to date)
@sanity/image-url                       1.0.2 (up to date)
@sanity/language-filter                 3.2.1 (up to date)
@sanity/preview-kit                     4.0.1 (up to date)
@sanity/types                          3.20.1 (up to date)
@sanity/ui                              1.9.3 (up to date)
@sanity/vision                         3.20.1 (up to date)
sanity                                 3.20.1 (up to date)

What operating system are you using?

Which versions of Node.js / npm are you running? npm -v && node -v

npm: 9.8.1 node: v18.18.2

Additional context:

// /sanity/client.ts
import { deskTool } from "sanity/desk";
import { visionTool } from "@sanity/vision";
import { PluginOptions, defineConfig } from "sanity";
import { languageFilter } from '@sanity/language-filter'

import { langs } from "@/encoded-url";
import { ApiIcon } from "@sanity/icons";
import { NEXT_PUBLIC_SANITY_DATASET_PRODUCTION, NEXT_PUBLIC_SANITY_DATASET_STAGING, NEXT_PUBLIC_SANITY_PROJECT_ID } from "@/utils/constants";
import { PAGES_NAME } from "@/sanity/schemas/constants";
import { i18nConfig } from "@/i18nConfig";

// Sanity plugins
import { settings, pages } from "@/sanity/plugins";

// Sanity schemas
import { schema } from "@/sanity/schemas";

const plugins: PluginOptions[] = [
    languageFilter({
        documentTypes: [PAGES_NAME], // <-- hangi sayfalar çevrilecek?
        defaultLanguages: [i18nConfig.defaultLocale],
        supportedLanguages: langs.map(m => ({ id: m.code, title: `${m.title} (${m.originalTitle})` })),
        filterField: (enclosingType, field, selectedLanguageIds) => !enclosingType.name.startsWith("locale") || selectedLanguageIds.includes(field.name),
    }),
    deskTool(pages),
    deskTool(settings),
];

export default defineConfig([
         // other configs and admin...
    {
        name: "admin",
        basePath: "/admin",
        projectId: NEXT_PUBLIC_SANITY_PROJECT_ID,
        dataset: NEXT_PUBLIC_SANITY_DATASET_PRODUCTION,
        schema,
        plugins: [
            ...plugins,
            visionTool({
                name: "groq-query",
                title: "Vision",
                icon: ApiIcon,
            }),
        ],
    }
]);
// sanity/sanity.config.tsx
import { deskTool } from "sanity/desk";
import { visionTool } from "@sanity/vision";
import { PluginOptions, defineConfig } from "sanity";
import { languageFilter } from '@sanity/language-filter'

import { langs } from "@/encoded-url";
import { ApiIcon } from "@sanity/icons";
import { NEXT_PUBLIC_SANITY_DATASET_PRODUCTION, NEXT_PUBLIC_SANITY_DATASET_STAGING, NEXT_PUBLIC_SANITY_PROJECT_ID } from "@/utils/constants";
import { PAGES_NAME } from "@/sanity/schemas/constants";
import { i18nConfig } from "@/i18nConfig";

// Sanity plugins
import { settings, pages } from "@/sanity/plugins";

// Sanity schemas
import { schema } from "@/sanity/schemas";

const plugins: PluginOptions[] = [
    languageFilter({
        documentTypes: [PAGES_NAME], // <-- hangi sayfalar çevrilecek?
        defaultLanguages: [i18nConfig.defaultLocale],
        supportedLanguages: langs.map(m => ({ id: m.code, title: `${m.title} (${m.originalTitle})` })),
        filterField: (enclosingType, field, selectedLanguageIds) => !enclosingType.name.startsWith("locale") || selectedLanguageIds.includes(field.name),
    }),
    deskTool(pages),
    deskTool(settings),
];

export default defineConfig([
    {
        name: "staging",
        basePath: "/staging",
        projectId: NEXT_PUBLIC_SANITY_PROJECT_ID,
        dataset: NEXT_PUBLIC_SANITY_DATASET_STAGING,
        schema,
        plugins: [
            ...plugins,
            visionTool({
                name: "groq-query",
                title: "Vision",
                icon: ApiIcon,
            }),
        ],
    },
    {
        name: "admin",
        basePath: "/admin",
        projectId: NEXT_PUBLIC_SANITY_PROJECT_ID,
        dataset: NEXT_PUBLIC_SANITY_DATASET_PRODUCTION,
        schema,
        plugins: [
            ...plugins,
            visionTool({
                name: "groq-query",
                title: "Vision",
                icon: ApiIcon,
            }),
        ],
    }
]);
// sanity/plugins/pages.tsx
import { upperFirst } from "lodash";
import { urls, langs } from "@/encoded-url";
import { SanityPluginInfos } from "./types";
import { PAGES_NAME } from "@/sanity/schemas/constants";
import { NEXT_PUBLIC_SANITY_API_VERSION } from "@/utils/constants";
import { DeskToolOptions, StructureBuilder, StructureResolverContext } from "sanity/desk";

import { TextIcon as icon, HomeIcon, EditIcon } from "@sanity/icons";

const plugin: SanityPluginInfos = {
    name: PAGES_NAME,
    title: upperFirst(PAGES_NAME),
    icon,
};

export const pages: DeskToolOptions = {
    name: PAGES_NAME,
    title: plugin.title,
    icon,
    structure: (S: StructureBuilder, context: StructureResolverContext) => {
        const { getClient, schema, currentUser } = context;
        return S.documentTypeList(plugin.name);
    },
};