From e2dfb03f6c0d31185b4d8c0fa5f10854d974caac Mon Sep 17 00:00:00 2001 From: samfairbairn Date: Sun, 5 May 2024 20:08:40 -0700 Subject: [PATCH] try importing chart async --- .github/workflows/publish-package.yml | 2 +- packages/storykit/package.json | 2 +- packages/storykit/rollup.config.js | 14 ++++++++++- .../IPARoyaltyChart/IPARoyaltyChart.tsx | 24 +++++++++++++++++-- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml index 5fb5cd2..84c35a4 100644 --- a/.github/workflows/publish-package.yml +++ b/.github/workflows/publish-package.yml @@ -3,7 +3,7 @@ name: publish on github on: push: branches: - - main + - feature/chart-ssr jobs: publish-gpr: diff --git a/packages/storykit/package.json b/packages/storykit/package.json index 3dadb0b..f41ba92 100644 --- a/packages/storykit/package.json +++ b/packages/storykit/package.json @@ -1,7 +1,7 @@ { "name": "@storyprotocol/storykit", "author": "storyprotocol engineering ", - "version": "0.1.2", + "version": "0.1.6-mrtest.7", "type": "module", "main": "dist/storyprotocol-storykit.cjs.js", "module": "dist/storyprotocol-storykit.esm.js", diff --git a/packages/storykit/rollup.config.js b/packages/storykit/rollup.config.js index 5ea9e6c..b712646 100644 --- a/packages/storykit/rollup.config.js +++ b/packages/storykit/rollup.config.js @@ -16,15 +16,27 @@ const config = [ file: packageJson.main, format: "cjs", sourcemap: true, + globals: { + // react: "React", + // "react-dom": "ReactDOM", + "react-apexcharts": "ApexCharts", + }, }, { file: packageJson.module, format: "esm", sourcemap: true, + globals: { + // react: "React", + // "react-dom": "ReactDOM", + "react-apexcharts": "ApexCharts", + }, }, ], plugins: [peerDepsExternal(), resolve(), commonjs(), typescript(), terser(), postcss()], - external: ["react/jsx-runtime"], + // external: ["react/jsx-runtime"], + // external: ["react/jsx-runtime", "react", "react-dom", "react-apexcharts"], + external: ["react/jsx-runtime", "react-apexcharts"], }, { input: "src/index.ts", diff --git a/packages/storykit/src/components/IPARoyaltyChart/IPARoyaltyChart.tsx b/packages/storykit/src/components/IPARoyaltyChart/IPARoyaltyChart.tsx index 84e646a..10dcae2 100644 --- a/packages/storykit/src/components/IPARoyaltyChart/IPARoyaltyChart.tsx +++ b/packages/storykit/src/components/IPARoyaltyChart/IPARoyaltyChart.tsx @@ -1,6 +1,7 @@ import { shortenAddress } from "@/lib/utils" import { useIPAssetContext } from "@/providers" -import Chart from "react-apexcharts" +import { useEffect, useState } from "react" +// import Chart from "react-apexcharts" import { Address } from "viem" import "../../global.css" @@ -10,6 +11,23 @@ function IPARoyaltyChart() { const { royaltyData } = useIPAssetContext() + // console.log("Chart", Chart) + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const [Chart, setChart] = useState(null) + useEffect(() => { + import("react-apexcharts").then((Component) => setChart(Component)) + }, []) + console.log("Chart", Chart) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + // let ApexChart = Chart ? (Chart as unknown as any)?.default || Chart : null + let ApexChart = Chart + console.log("ApexChart 1", ApexChart) + if (ApexChart?.default) ApexChart = ApexChart.default + console.log("ApexChart 2", ApexChart) + if (ApexChart?.default) ApexChart = ApexChart.default + console.log("ApexChart 3", ApexChart) + if (royaltyData?.targetAncestors) { const chart = { options: { @@ -70,7 +88,9 @@ function IPARoyaltyChart() { return (
- + {ApexChart ? ( + + ) : null}