Compare commits
9 Commits
v2.3.29-rc
...
v2.3.32
| Author | SHA1 | Date | |
|---|---|---|---|
| 60422da644 | |||
| fc6da4e9aa | |||
| f7411d3dc4 | |||
| 7be2ec605c | |||
| bd00175912 | |||
| 9c9663eb88 | |||
| 402b5c30c6 | |||
| 2bb0381de4 | |||
| 614b0a5ffd |
@@ -61,7 +61,7 @@ export async function sendContactFormAction(formData: FormData) {
|
||||
productName,
|
||||
message,
|
||||
};
|
||||
fs.appendFileSync(backupFile, JSON.stringify(leadData) + '\\n');
|
||||
fs.appendFileSync(backupFile, JSON.stringify(leadData) + '\n');
|
||||
logger.info('Successfully saved lead to local backup file', { backupFile });
|
||||
} catch (backupError) {
|
||||
logger.error('Failed to write to local leads backup', { error: String(backupError) });
|
||||
@@ -156,7 +156,7 @@ export async function sendContactFormAction(formData: FormData) {
|
||||
|
||||
// Notify via Gotify (Internal)
|
||||
await services.notifications.notify({
|
||||
title: `📩 ${notificationSubject}`,
|
||||
title: `📩 [KLZ] ${notificationSubject}`,
|
||||
message: `New message from ${name} (${email}):\n\n${message}`,
|
||||
priority: 5,
|
||||
});
|
||||
|
||||
@@ -65,11 +65,8 @@ export async function getPostBySlug(slug: string, locale: string): Promise<PostD
|
||||
const fileContent = await fs.readFile(filePath, 'utf-8');
|
||||
const { data, content } = matter(fileContent);
|
||||
|
||||
// Fix MDX data props dropped by next-mdx-remote
|
||||
// Payload serializes as data={{"items":...}} which Acorn treats as a Block statement.
|
||||
const fixedContent = content.replace(/data=\{\{([\s\S]*?)\}\}/g, (match, p1) => {
|
||||
return 'data="{' + p1.replace(/"/g, '"') + '}"';
|
||||
});
|
||||
const { fixMdxDataProps } = await import('./mdx-utils');
|
||||
const fixedContent = fixMdxDataProps(content);
|
||||
|
||||
let parsedContent = fixedContent;
|
||||
try {
|
||||
|
||||
68
lib/mdx-utils.ts
Normal file
68
lib/mdx-utils.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
export function fixMdxDataProps(content: string): string {
|
||||
let fixedContent = content;
|
||||
let dataIndex = fixedContent.indexOf('data={{');
|
||||
|
||||
while (dataIndex !== -1) {
|
||||
let openCount = 0;
|
||||
let endIndex = -1;
|
||||
const startObj = dataIndex + 6; // index of the first '{' in 'data={{'
|
||||
|
||||
let inString = false;
|
||||
let isEscaped = false;
|
||||
|
||||
for (let i = startObj; i < fixedContent.length; i++) {
|
||||
const char = fixedContent[i];
|
||||
|
||||
if (isEscaped) {
|
||||
isEscaped = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (char === '\\') {
|
||||
isEscaped = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (char === '"') {
|
||||
inString = !inString;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!inString) {
|
||||
if (char === '{') {
|
||||
openCount++;
|
||||
} else if (char === '}') {
|
||||
openCount--;
|
||||
if (openCount === 0) {
|
||||
endIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (endIndex !== -1) {
|
||||
// jsonStr is the content INSIDE the outer curly braces
|
||||
const jsonStr = fixedContent.substring(startObj + 1, endIndex);
|
||||
const safeJsonStr = jsonStr.replace(/"/g, '"');
|
||||
const replacement = `data="{${safeJsonStr}}"`;
|
||||
|
||||
// We also need to consume the closing `}` of the `data={{`
|
||||
const nextCharIndex = endIndex + 1;
|
||||
const skipChars =
|
||||
nextCharIndex < fixedContent.length && fixedContent[nextCharIndex] === '}' ? 2 : 1;
|
||||
|
||||
fixedContent =
|
||||
fixedContent.substring(0, dataIndex) +
|
||||
replacement +
|
||||
fixedContent.substring(endIndex + skipChars);
|
||||
|
||||
dataIndex = fixedContent.indexOf('data={{', dataIndex + replacement.length);
|
||||
} else {
|
||||
// Malformed braces, prevent infinite loop
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return fixedContent;
|
||||
}
|
||||
@@ -53,11 +53,8 @@ export async function getPageBySlug(slug: string, locale: string): Promise<PageD
|
||||
const fileContent = await fs.readFile(filePath, 'utf-8');
|
||||
const { data, content } = matter(fileContent);
|
||||
|
||||
// Fix MDX data props dropped by next-mdx-remote
|
||||
// Payload serializes as data={{"items":...}} which Acorn treats as a Block statement.
|
||||
const fixedContent = content.replace(/data=\{\{([\s\S]*?)\}\}/g, (match, p1) => {
|
||||
return 'data="{' + p1.replace(/"/g, '"') + '}"';
|
||||
});
|
||||
const { fixMdxDataProps } = await import('./mdx-utils');
|
||||
const fixedContent = fixMdxDataProps(content);
|
||||
|
||||
let parsedContent = fixedContent;
|
||||
try {
|
||||
|
||||
@@ -39,11 +39,8 @@ export async function getProductBySlug(slug: string, locale: string): Promise<Pr
|
||||
const fileContent = await fs.readFile(filePath, 'utf-8');
|
||||
const { data, content } = matter(fileContent);
|
||||
|
||||
// Fix MDX data props dropped by next-mdx-remote
|
||||
// Payload serializes as data={{"items":...}} which Acorn treats as a Block statement.
|
||||
const fixedContent = content.replace(/data=\{\{([\s\S]*?)\}\}/g, (match, p1) => {
|
||||
return 'data="{' + p1.replace(/"/g, '"') + '}"';
|
||||
});
|
||||
const { fixMdxDataProps } = await import('./mdx-utils');
|
||||
const fixedContent = fixMdxDataProps(content);
|
||||
|
||||
let parsedContent = fixedContent;
|
||||
try {
|
||||
|
||||
@@ -56,6 +56,11 @@ export class GlitchtipErrorReportingService implements ErrorReportingService {
|
||||
tracesSampleRate: this.options.tracesSampleRate ?? 0.1,
|
||||
replaysOnErrorSampleRate: 1.0,
|
||||
replaysSessionSampleRate: 0.1,
|
||||
ignoreErrors: [
|
||||
'ChunkLoadError',
|
||||
'Failed to fetch dynamically imported module',
|
||||
'Failed to find Server Action',
|
||||
],
|
||||
});
|
||||
}
|
||||
return Sentry;
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
"prepare": "husky",
|
||||
"preinstall": "npx only-allow pnpm"
|
||||
},
|
||||
"version": "2.3.29-rc.1",
|
||||
"version": "2.3.32",
|
||||
"pnpm": {
|
||||
"onlyBuiltDependencies": [
|
||||
"@parcel/watcher",
|
||||
|
||||
@@ -12,4 +12,5 @@ Sentry.init({
|
||||
|
||||
// Setting this option to true will print useful information to the console while you're setting up Sentry.
|
||||
debug: false,
|
||||
ignoreErrors: ['failed to pipe response'],
|
||||
});
|
||||
|
||||
@@ -12,4 +12,5 @@ Sentry.init({
|
||||
|
||||
// Setting this option to true will print useful information to the console while you're setting up Sentry.
|
||||
debug: false,
|
||||
ignoreErrors: ['failed to pipe response'],
|
||||
});
|
||||
|
||||
47
tests/glitchtip-error-reporting.test.ts
Normal file
47
tests/glitchtip-error-reporting.test.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { GlitchtipErrorReportingService } from '../lib/services/errors/glitchtip-error-reporting-service';
|
||||
|
||||
// Mock the LoggerService
|
||||
const mockLogger = {
|
||||
child: vi.fn().mockReturnThis(),
|
||||
info: vi.fn(),
|
||||
error: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
debug: vi.fn(),
|
||||
} as any;
|
||||
|
||||
const mockSentryInit = vi.fn();
|
||||
|
||||
vi.mock('@sentry/nextjs', () => ({
|
||||
init: (...args: any[]) => mockSentryInit(...args),
|
||||
captureException: vi.fn(),
|
||||
captureMessage: vi.fn(),
|
||||
}));
|
||||
|
||||
describe('GlitchtipErrorReportingService', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should ignore version drift errors (ChunkLoadError and Server Action) in Sentry config', async () => {
|
||||
// Simulate window to force client-side init behavior instantly
|
||||
const originalWindow = global.window;
|
||||
global.window = {
|
||||
requestIdleCallback: (cb: Function) => cb(),
|
||||
} as any;
|
||||
|
||||
const service = new GlitchtipErrorReportingService({ enabled: true }, mockLogger);
|
||||
|
||||
// Give the dynamic import a moment to resolve
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
|
||||
expect(mockSentryInit).toHaveBeenCalledOnce();
|
||||
const initCallArgs = mockSentryInit.mock.calls[0][0];
|
||||
|
||||
expect(initCallArgs.ignoreErrors).toBeDefined();
|
||||
expect(initCallArgs.ignoreErrors).toContain('ChunkLoadError');
|
||||
expect(initCallArgs.ignoreErrors).toContain('Failed to find Server Action');
|
||||
|
||||
global.window = originalWindow;
|
||||
});
|
||||
});
|
||||
22
tests/mdx-regex.test.ts
Normal file
22
tests/mdx-regex.test.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { fixMdxDataProps } from '../lib/mdx-utils';
|
||||
|
||||
describe('MDX Data Props Fixer', () => {
|
||||
it('should correctly parse MDX with nested JSON containing }}', () => {
|
||||
// This string simulates the exact structure that causes the bug in n2x2y.mdx
|
||||
const mdxInput = `<Block type="productTabs" data={{"content":{"root":{"children":[]}},"id":"123"}} />`;
|
||||
|
||||
const result = fixMdxDataProps(mdxInput);
|
||||
|
||||
const expected = `<Block type="productTabs" data="{"content":{"root":{"children":[]}},"id":"123"}" />`;
|
||||
|
||||
expect(result).toBe(expected);
|
||||
});
|
||||
|
||||
it('should not prematurely truncate if } appears inside a string literal', () => {
|
||||
const mdxInput = `<Block type="productTabs" data={{"content":{"text":"}>"}}} />`;
|
||||
const result = fixMdxDataProps(mdxInput);
|
||||
const expected = `<Block type="productTabs" data="{"content":{"text":"}>"}}" />`;
|
||||
expect(result).toBe(expected.replace('>', '>'));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user