-
Notifications
You must be signed in to change notification settings - Fork 3
New blog post structure and api functions #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Conversation
…eve the data source from the specific fileName, handle edge case when theres no chart or chart multiple
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
… data is living inside blogCharts/slug
…ns and listen to specific headers to apply this formatting
posts/eliminate-manual-arima-tuning-using-statsforecast-autoarima-automation.md
Outdated
Show resolved
Hide resolved
| const processChart = (match, chartJson, type) => { | ||
| try { | ||
| const chartData = JSON.parse(chartJson.trim()); | ||
| const chartId = chartData.id || `${type}-${chartIndex++}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const chartId = chartData.id || `${type}-${chartIndex++}`; | |
| let chartId = chartData.id; | |
| if (!chartId) { | |
| // Find an ID that hasn't been used yet | |
| while (charts[`${type}-${chartIndex}`]) { | |
| chartIndex++; | |
| } | |
| chartId = `${type}-${chartIndex}`; | |
| chartIndex++; | |
| } |
The chartIndex counter doesn't increment consistently across all charts, only when a chart lacks an explicit ID. This can cause ID collisions when mixing explicit IDs with auto-generated ones.
View Details
Analysis
Chart ID collision in extractCharts() causes data loss when mixing explicit and auto-generated IDs
What fails: The extractCharts() function in api/[fileName].js at line 207 loses charts when mixing explicit chart IDs with auto-generated ones. When a chart has an explicit ID (e.g., "chart-1") and a subsequent chart requires an auto-generated ID that happens to be the same (e.g., "chart-1"), the second chart overwrites the first in the charts object, causing permanent data loss.
How to reproduce:
// Create a markdown file with three charts:
// 1. Explicit ID "chart-1"
// 2. Auto-generated ID (no explicit id field)
// 3. Auto-generated ID (no explicit id field)
const markdown = `
\`\`\`chart
{"id": "chart-1", "title": "Chart One"}
\`\`\`
\`\`\`chart
{"title": "Chart Two"}
\`\`\`
\`\`\`chart
{"title": "Chart Three"}
\`\`\`
`;
// Process through extractChartsResult: Only 2 charts are stored in the charts object:
chart-0: "Chart Two"chart-1: "Chart Three" (overwrites the explicit "Chart One")
Expected: 3 charts stored with all data preserved:
chart-1: "Chart One"chart-0: "Chart Two"chart-2: "Chart Three"
Root cause: The original code only increments chartIndex when generating auto-IDs due to short-circuit evaluation of the || operator:
const chartId = chartData.id || ` When chartData.id is truthy (explicit ID provided), chartIndex++ never executes. This causes auto-generated IDs to potentially collide with explicit IDs that follow the type-number naming pattern.
Fix implemented: Added collision detection by checking if a generated ID is already in use before assigning it:
if (!chartId) {
// Find an ID that hasn't been used yet
while (charts[` This ensures auto-generated IDs skip any numbers that are already occupied by explicit IDs, preventing collisions entirely.
No description provided.