Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ jobs:
build: npm run build
- demo: demos/scichart-react-next
build: npm run build
# React 19 on Vite and the server-rendering frameworks; their builds do not
# typecheck by themselves, except Vite's
- demo: demos/vite-react
build: npm run build
- demo: demos/react-router
build: npm run typecheck && npm run build
- demo: demos/tanstack-start
build: npm run typecheck && npm run build
- demo: demos/astro-react
build: npm run check && npm run build
# electron-forge exposes no compile-only command, so packaging is the build.
# It downloads an Electron binary, which is why this leg is the slow one.
- demo: demos/electron
Expand Down
6 changes: 6 additions & 0 deletions demos/astro-react/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Astro build output and generated types
dist/
.astro/

# WASM binaries copied in by scripts/copy-wasm.mjs
public/*.wasm
46 changes: 46 additions & 0 deletions demos/astro-react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# scichart-react on Astro (React islands)

A static [Astro](https://astro.build) page with two SciChart.js charts as React 19 islands:

- [`src/components/InitChartIsland.tsx`](./src/components/InitChartIsland.tsx): `SciChartReact` with an
`initChart` function.
- [`src/components/DeclarativeChartIsland.tsx`](./src/components/DeclarativeChartIsland.tsx):
`SciChartDeclarative` with a Builder API `config`.
- [`src/pages/index.astro`](./src/pages/index.astro): the page that mounts both.

The islands use `client:only="react"`. The other directives (`client:load`, `client:visible`, ...) still
render the component on the server first, which a WebGL/WebAssembly chart cannot do. Each island sits in a
`.chart-frame` element that is part of the static HTML, so the page reserves the chart's space before any
JavaScript runs.

## Running

The demo uses the repository's own build of the wrapper (`"scichart-react": "file:../../lib"`), so build it
first from the repository root:

```bash
npm install
npm run build
```

Then, in this folder:

```bash
npm install
npm run dev # http://localhost:4321
npm run build # static build into dist/
npm run preview # serve dist/ on http://localhost:4321
npm run check # astro check (types for .astro and .tsx)
```

`dev`, `build` and `check` first copy SciChart's WebAssembly files from `node_modules/scichart/_wasm/` into
`public/` (`scripts/copy-wasm.mjs`). The browser loads them from `/scichart.wasm`, the default location
`scichart-react` configures.

## Worth knowing

- Astro 7 can run `astro dev` as a background server. If `npm run dev` returns straight away, the server is
still running: `npx astro dev status` shows it and `npx astro dev stop` stops it.
- `astro.config.mjs` sets `vite.resolve.dedupe` because the wrapper is linked from `../../lib`; without it
a second copy of SciChart.js would be bundled. An app that installs `scichart-react` from npm does not
need this.
37 changes: 37 additions & 0 deletions demos/astro-react/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// @ts-check
import { defineConfig } from "astro/config";
import react from "@astrojs/react";

/**
* Astro configuration for the scichart-react demo.
*
* `resolve.dedupe` is the load-bearing setting. `scichart-react` is installed with `file:../../lib`,
* which npm materialises as a symlink. Vite resolves symlinks to their real path, so the wrapper's
* own `import "scichart"` is resolved starting from the repository root — where a second copy of
* `scichart` is installed. Two copies means two WebAssembly engine instances and a chart that
* silently misbehaves. Deduping forces every one of these bare specifiers to resolve from this
* demo's own `node_modules`. It is the Vite equivalent of the webpack alias in the Next.js demo.
* Removing it is measurable: the client bundle grows from ~2.0 MB to ~3.2 MB and `dist/_astro/`
* gains a second SciChart engine chunk.
*
* `optimizeDeps.include` is a dev-server ergonomics setting, not a correctness one. Vite does not
* pre-bundle linked (`file:`) dependencies, so without it `scichart-react` is served as a raw
* module graph out of `/@fs/<repo>/lib/esm/*`, one request per file. Listing it produces a single
* pre-bundled chunk instead. `scichart` is listed alongside it so the pre-bundle stays a shared
* chunk even in an app that never imports `scichart` directly. Neither entry affects `astro build`,
* and neither is what prevents the duplicate copy — that is `dedupe` above.
*
* Note there is deliberately no `ssr.noExternal` entry: it was measured to make no difference here,
* because `client:only` islands never enter the server module graph in the first place. See README.
*/
export default defineConfig({
integrations: [react()],
vite: {
resolve: {
dedupe: ["react", "react-dom", "scichart", "scichart-react"]
},
optimizeDeps: {
include: ["scichart", "scichart-react"]
}
}
});
Loading
Loading