Skip to content

Commit fd3244d

Browse files
daffaromeroclaude
andcommitted
fix: filter phantom LAMPIRAN child BABs by applying hasDescendantPasal to all structural nodes
Remove the unconditional short-circuit that passed any structural node with a non-null parent_id through the babNodes filter. Phantom TOC-BABs inside a LAMPIRAN have parent_id = lampiran_db_id (non-null), so the guard was letting them through despite having zero pasal descendants. Applying hasDescendantPasal() to every structural node regardless of depth fixes UU 6/2023 (Cipta Kerja): the duplicated TOC BABs parsed from the LAMPIRAN TOC pages are now correctly filtered out while real BABs and their Bagian/Paragraf sub-sections remain (they ARE in structuralIdsWithPasals). Co-authored-by: Claude <noreply@anthropic.com>
1 parent 35f080f commit fd3244d

File tree

1 file changed

+11
-10
lines changed
  • apps/web/src/app/[locale]/peraturan/[type]/[slug]

1 file changed

+11
-10
lines changed

apps/web/src/app/[locale]/peraturan/[type]/[slug]/page.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -330,19 +330,20 @@ async function LawReaderSection({
330330
return false;
331331
}
332332

333-
// Filter out structural nodes (BABs, Bagians) that have no pasal content in the DB.
333+
// Filter out structural nodes (BABs, Bagians, etc.) that have no pasal content in the DB.
334334
// This removes table-of-contents entries that the parser mistakenly captures as structural
335335
// nodes — common in ratification laws (e.g. UU 6/2023) where the attached law's TOC
336336
// appears verbatim and gets parsed as BAB markers without any associated Pasal content.
337-
// Only top-level structural nodes (BAB / aturan / lampiran — those without a parent) are
338-
// filtered; sub-sections (Bagian, Paragraf) are kept as-is under their parent BAB.
339-
const babNodes = allStructuralNodes.filter((node) => {
340-
// Keep sub-sections unconditionally — they're filtered indirectly via their parent BAB.
341-
if (node.parent_id !== null) return true;
342-
// For top-level structural nodes, keep only those with at least one pasal at any depth
343-
// (handles BAB → Bagian → Paragraf → Pasal nesting, not just direct children).
344-
return hasDescendantPasal(node.id);
345-
});
337+
//
338+
// We apply hasDescendantPasal() to EVERY structural node regardless of depth or parent_id.
339+
// Previously there was a short-circuit `if (node.parent_id !== null) return true` here,
340+
// but that incorrectly passed phantom TOC-BABs that live inside a LAMPIRAN node (they have
341+
// a non-null parent_id pointing to the lampiran, but still have zero pasal descendants).
342+
// Real Bagian/Paragraf nodes also have non-null parent_ids but pass the check because they
343+
// ARE in structuralIdsWithPasals (pasals are direct children). The renderer handles
344+
// sub-section grouping via subSectionIds — it never renders a structural node independently
345+
// unless it's the top-level BAB iteration below.
346+
const babNodes = allStructuralNodes.filter((node) => hasDescendantPasal(node.id));
346347

347348
const mainContent = (
348349
<>

0 commit comments

Comments
 (0)