@revolist/svelte-charts 3.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -87,7 +87,9 @@ so do not destroy its ref yourself.
87
87
  Creation and updates are asynchronous. Pending work is cancelled on unmount or
88
88
  superseding configuration, and stale results are destroyed. Failures call
89
89
  `options.onError`, or `console.error` when no error handler is supplied. Server
90
- rendering produces an empty host; chart creation starts after client mounting.
90
+ rendering produces an empty host by default. Pass the optional `serverRender`
91
+ result from `renderChartToSVG` to include initial SVG and hydrate it on mounting.
92
+ See the engine's [server rendering guide](../../docs/server-rendering.md).
91
93
 
92
94
  ## Building and distribution
93
95
 
@@ -1,23 +1,26 @@
1
1
  <script lang="ts">
2
- import { onMount } from 'svelte';
2
+ import { onMount, untrack } from 'svelte';
3
3
  import type { HTMLAttributes } from 'svelte/elements';
4
4
  import { createChartComponentController } from '@revolist/charts/framework';
5
5
  import type { ChartComponentController, ChartComponentOptions } from '@revolist/charts/framework';
6
- import type { ChartRef } from '@revolist/charts';
6
+ import type { ChartRef, ChartServerRender } from '@revolist/charts';
7
7
 
8
8
  interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
9
9
  options: ChartComponentOptions;
10
10
  onReady?: (chart: ChartRef) => void;
11
+ serverRender?: ChartServerRender;
11
12
  }
12
- let { options, onReady, style = '', ...attributes }: Props = $props();
13
+ let { options, onReady, serverRender, style = '', ...attributes }: Props = $props();
14
+ // Snapshot markup belongs to the initial mount, not subsequent prop updates.
15
+ const initial = untrack(() => serverRender);
13
16
  let host: HTMLDivElement;
14
17
  let controller: ChartComponentController | undefined;
15
18
  onMount(() => {
16
- controller = createChartComponentController(host, chart => onReady?.(chart));
19
+ controller = createChartComponentController(host, chart => onReady?.(chart), !!initial);
17
20
  void controller.setOptions(options);
18
21
  return () => { controller?.destroy(); controller = undefined; };
19
22
  });
20
23
  $effect(() => { const next = options; void controller?.setOptions(next); });
21
24
  </script>
22
25
 
23
- <div {...attributes} bind:this={host} style={`width:100%;height:300px;${style}`}></div>
26
+ <div {...attributes} bind:this={host} style={`width:100%;height:${initial?.height ?? 300}px;${style}`}>{@html initial?.svg ?? ''}</div>
@@ -1,9 +1,10 @@
1
1
  import type { HTMLAttributes } from 'svelte/elements';
2
2
  import type { ChartComponentOptions } from '@revolist/charts/framework';
3
- import type { ChartRef } from '@revolist/charts';
3
+ import type { ChartRef, ChartServerRender } from '@revolist/charts';
4
4
  interface Props extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
5
5
  options: ChartComponentOptions;
6
6
  onReady?: (chart: ChartRef) => void;
7
+ serverRender?: ChartServerRender;
7
8
  }
8
9
  declare const RevoChart: import("svelte").Component<Props, {}, "">;
9
10
  type RevoChart = ReturnType<typeof RevoChart>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revolist/svelte-charts",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "description": "Svelte components for RevoGrid Charts",
5
5
  "type": "module",
6
6
  "license": "Commercial",
@@ -20,7 +20,7 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "@revolist/charts": "3.0.3"
23
+ "@revolist/charts": "3.0.4"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "svelte": "^5.55.0"