From 4d8fc6439c3129e346dbdff03f0e20ef029cd1a0 Mon Sep 17 00:00:00 2001 From: Paddy Mullen Date: Sun, 24 May 2026 17:49:09 -0400 Subject: [PATCH 1/2] fix(js): export parquetRead/parquetMetadata from static-embed.js (#857) Callers can now import these from the sidecar bundle to decode a raw parquet ArrayBuffer (e.g. from fetch()) without going through base64. resolveDFDataAsync and preResolveDFDataDict are exported too so a page can fully orchestrate its own init before the auto-mount fires. Co-Authored-By: Claude Sonnet 4.6 --- packages/js/static-embed.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/js/static-embed.tsx b/packages/js/static-embed.tsx index 5e57f3767..0155b7bcb 100644 --- a/packages/js/static-embed.tsx +++ b/packages/js/static-embed.tsx @@ -3,6 +3,11 @@ import * as ReactDOM from "react-dom/client"; import { BuckarooStaticTable, resolveDFDataAsync, preResolveDFDataDict } from "buckaroo-js-core"; import "../buckaroo-js-core/dist/style.css"; +// Named exports so callers can import parquetRead from static-embed.js directly +// and feed raw ArrayBuffer parquet (e.g. from fetch()) without base64 encoding. +export { parquetRead, parquetMetadata } from "hyparquet"; +export { resolveDFDataAsync, preResolveDFDataDict } from "buckaroo-js-core"; + async function main() { const dataEl = document.getElementById("buckaroo-data"); if (!dataEl?.textContent) { From 7cc369bdb9dcdbe679549e6adc8520b0e41ec3f2 Mon Sep 17 00:00:00 2001 From: Paddy Mullen Date: Sun, 24 May 2026 21:40:16 -0400 Subject: [PATCH 2/2] fix(js): add renderArtifact export and idle main() for library use - Route parquetRead/parquetMetadata re-export through buckaroo-js-core so the parquet decoder has a single source of truth. - Extract the render logic from main() into an exported renderArtifact(rootEl, artifact) so callers that fetch raw parquet at runtime can build an artifact and trigger the same render the auto-init runs. - Have main() silently skip when no #buckaroo-data is present, letting the bundle be imported purely as a library (for parquetRead/renderArtifact) without a spurious "No #buckaroo-data script block found" console error. Co-Authored-By: Claude Opus 4.7 (1M context) --- packages/js/static-embed.tsx | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/js/static-embed.tsx b/packages/js/static-embed.tsx index 0155b7bcb..9a8ebb809 100644 --- a/packages/js/static-embed.tsx +++ b/packages/js/static-embed.tsx @@ -5,20 +5,14 @@ import "../buckaroo-js-core/dist/style.css"; // Named exports so callers can import parquetRead from static-embed.js directly // and feed raw ArrayBuffer parquet (e.g. from fetch()) without base64 encoding. -export { parquetRead, parquetMetadata } from "hyparquet"; -export { resolveDFDataAsync, preResolveDFDataDict } from "buckaroo-js-core"; - -async function main() { - const dataEl = document.getElementById("buckaroo-data"); - if (!dataEl?.textContent) { - throw new Error("No #buckaroo-data script block found"); - } - const artifact = JSON.parse(dataEl.textContent); - - const rootEl = document.getElementById("root"); - if (!rootEl) throw new Error("No #root element found"); - - // Pre-resolve parquet_b64 payloads before React render +// Re-exported via buckaroo-js-core (which re-exports from hyparquet) to keep a +// single source of truth for the parquet decoder. +export { parquetRead, parquetMetadata, resolveDFDataAsync, preResolveDFDataDict } from "buckaroo-js-core"; + +// Resolve any parquet_b64 payloads in the artifact and render it into rootEl. +// Exported so callers that fetch raw parquet (via the exported parquetRead) +// can build an artifact at runtime and trigger the same render main() does. +export async function renderArtifact(rootEl: HTMLElement, artifact: any) { const [dfData, summaryStatsData] = await Promise.all([ resolveDFDataAsync(artifact.df_data), resolveDFDataAsync(artifact.summary_stats_data), @@ -31,11 +25,9 @@ async function main() { summary_stats_data: summaryStatsData, }; - // For Buckaroo mode, pre-resolve all parquet_b64 values in df_data_dict if (artifact.embed_type === "Buckaroo" && artifact.df_data_dict) { resolved.df_display_args = artifact.df_display_args; resolved.df_data_dict = await preResolveDFDataDict(artifact.df_data_dict); - // Ensure "main" key has the already-resolved data resolved.df_data_dict["main"] = dfData; resolved.df_meta = artifact.df_meta; resolved.buckaroo_options = artifact.buckaroo_options; @@ -50,6 +42,16 @@ async function main() { ); } +async function main() { + const dataEl = document.getElementById("buckaroo-data"); + // When the bundle is imported purely as a library (for parquetRead / renderArtifact), + // there is no #buckaroo-data; silently skip auto-init instead of erroring. + if (!dataEl?.textContent) return; + const rootEl = document.getElementById("root"); + if (!rootEl) throw new Error("No #root element found"); + await renderArtifact(rootEl, JSON.parse(dataEl.textContent)); +} + main().catch((e) => { console.error("Buckaroo static embed init failed:", e); const rootEl = document.getElementById("root");