Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core-web/libs/sdk/client/src/lib/client/page/page-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ describe('PageClient', () => {
});

it('should omit styleEditorSchemas and log debug when schema endpoint fails', async () => {
const consolaDebugSpy = jest.spyOn(consola, 'debug');
const consolaDebugSpy = jest.spyOn(console, 'warn');

mockRequest.mockImplementation((url: string) => {
if (url.includes('/contenttype-schema')) {
Expand Down Expand Up @@ -917,7 +917,7 @@ describe('PageClient', () => {
});

it('should warn and return empty when pageId is missing from the page response', async () => {
const consolaWarnSpy = jest.spyOn(consola, 'warn');
const consolaWarnSpy = jest.spyOn(console, 'warn');

mockRequest.mockResolvedValue({
...mockGraphQLResponse,
Expand Down
16 changes: 9 additions & 7 deletions core-web/libs/sdk/client/src/lib/client/page/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
jest.mock('consola');

import { consola } from 'consola';

import { buildPageQuery, buildQuery, mapContentResponse } from './utils';

describe('buildPageQuery()', () => {
Expand Down Expand Up @@ -42,20 +38,26 @@ describe('buildPageQuery()', () => {
});

it('does not warn when verbose is false and no page provided', () => {
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => undefined);
buildPageQuery({ verbose: false });
expect(consola.warn).not.toHaveBeenCalled();
expect(warnSpy).not.toHaveBeenCalled();
warnSpy.mockRestore();
});

it('does not warn when page is provided even with verbose=true', () => {
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => undefined);
buildPageQuery({ page: 'title', verbose: true });
expect(consola.warn).not.toHaveBeenCalled();
expect(warnSpy).not.toHaveBeenCalled();
warnSpy.mockRestore();
});

it('warns when verbose=true and no page fragment is provided', () => {
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => undefined);
buildPageQuery({ verbose: true });
expect(consola.warn).toHaveBeenCalledWith(
expect(warnSpy).toHaveBeenCalledWith(
expect.stringContaining('No page query was found')
);
warnSpy.mockRestore();
});
});

Expand Down
28 changes: 7 additions & 21 deletions core-web/libs/sdk/client/src/lib/client/page/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { consola } from 'consola';

import {
DotCMSClientConfig,
DotGraphQLApiResponse,
DotHttpClient,
DotHttpError,
DotRequestOptions
DotCMSClientConfig,
DotGraphQLApiResponse,
DotHttpClient,
DotRequestOptions
} from '@dotcms/types';
import { StyleEditorFormSchema } from '@dotcms/types/internal';

Expand Down Expand Up @@ -60,7 +57,7 @@ export const buildPageQuery = ({
verbose?: boolean;
}) => {
if (!page && verbose) {
consola.warn(
console.warn(
"[DotCMS Client]: No page query was found, so we're loading all content using _map. This might slow things down. For better performance, we recommend adding a specific query in the page attribute."
);
}
Expand Down Expand Up @@ -285,12 +282,8 @@ export async function fetchStyleEditorSchemas(
requestOptions: DotRequestOptions,
httpClient: DotHttpClient
): Promise<StyleEditorFormSchema[]> {
if (typeof window === 'undefined') {
return [];
}

if (!pageId) {
consola.warn(
console.warn(
'[DotCMS PageClient]: fetchStyleEditorSchemas called without a pageId — ' +
'make sure "identifier" is included in your GraphQL page fragment.'
);
Expand Down Expand Up @@ -318,14 +311,7 @@ export async function fetchStyleEditorSchemas(

return entity as StyleEditorFormSchema[];
} catch (error) {
if (error instanceof DotHttpError && (error.status === 401 || error.status === 403)) {
consola.warn(
`[DotCMS PageClient]: Style editor schemas request failed with ${error.status} — ` +
'make sure your DotCMS client is configured with a valid authToken that has READ access to the page.'
);
Comment thread
KevinDavilaDotCMS marked this conversation as resolved.
} else {
consola.debug('[DotCMS PageClient]: Skipping style editor schemas:', error);
}
console.warn('[DotCMS PageClient]: Skipping style editor schemas:', error);

return [];
}
Expand Down
1 change: 0 additions & 1 deletion examples/nextjs/src/app/[[...slug]]/page.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { redirect } from "next/navigation";
import NotFound from "@/app/not-found";
import { ErrorPage, ERROR_COPY } from "@/components/error";
import { Page } from "@/views/Page";
import { getDotCMSPage } from "@/utils/getDotCMSPage";
import { Page } from "@/views/Page";

Expand Down
Loading