-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does not work well in an SSR application #36
Comments
Please describe your configuration: bundler, node version, dev server and package manager. I will try to reproduce this problem. My package is not well defined esmodule because it does not contain "type": "module" in package.json and does not use imports with file extensions. But it is easy to run it in sveltekit or bundle via webpack. Maybe I will able to make a workaround for your configuration. I want to notice that the base package (lightweight-charts) currently does not support SSR at all. It will crash in node environment due to dom api calls (there is a workaround but it also depends on config). This should be fixed in lightweight-chart@4.0.0 but it is still not yet released =( |
Hey there, thanks for your prompt response. Here's my config inside svelte.config.js import adapter from '@sveltejs/adapter-auto';
import preprocess from 'svelte-preprocess';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: [
preprocess({
postcss: true
})
],
kit: {
adapter: adapter(),
vits: {
optimizeDeps: {
include: ['lightweight-charts', 'svelte-lightweight-charts']
}
}
}
};
export default config; I'm on node v16.15.0, I use npm, and I use the default sveltekit dev server through npm run dev. |
Ok, I see this warning on my side. You need to add:
This will prevent
Unfortunately this one requires some changes to my package. I will try to figure out how I can fix this and release a new version. It looks like a warning not a blocker. If you have any further problems feel free to write me. |
This will do for now. Thank you |
Unfortunately, adding this to my config did not solve the issue and I still get error |
Try removing |
I've published next beta. Try Add to your config:
This version should run without any warnings and should reserve space for the chart in SSR. This means that there will be no "jumps" when the chart is initialized. |
@trash-and-fire Hey, it looks like the lib stopped working after the recent sveltekit changes. I moved the following into my vite.config.js
vite.config.js
Here is a minimal repo to reproduce the errors: |
Yes, svelte-kit has had many breaking changes and is currently in a very unstable state. You are correct in moving the ssr section to Try using I'll try it myself with the latest version of svelte-kit when I have time. |
I followed the instructions and got the following error
Here's what I did:
my vite.config.js
I have also pushed the above changes to the minimal repo I linked in my previous comment. |
I fixed dev mode with this config.
Unfortunately preview/build mode is not working yet. I'm trying to figure out why. |
Oh, I'm confused with the commands.. Build preview also works. |
The next version will be 2.0.0 with 4.0.0 charts which should work on server rendering without any extra effort. |
I added fancy-canvas to my noExternals and got this error
|
Try removing |
Yes, I did it with your repo. Note that there is no |
Did the chart actually render for you? I just see a big black rectangle |
There is no |
My bad, it works now. Thanks for your assistance |
@trash-and-fire Hey there brother, quick question. How would I access the chart container to add UI elements as seen below? Your doc states that the container property can be used in the config like so:
But unfortunately, that did not work for me due to |
See an example of a legend. This is close to what you want to do. As for the properties of the container, they are slightly for other situations. |
Your doc mentions that Also, the code snippet from your example logs function handleCrosshairMove({ detail: param }) {
if (param.time) {
const price = param.seriesPrices.get(CandlestickSeries);
console.log(price);
} else return;
} I tried to access the price data via I am able to view the OHLC data with Do you know why this happens? |
I would recommend using A chart instance reference is also available, but should be used for one-time actions such as taking a screenshot or fitting content.
In your case, I think the problem is the
And then you can use |
Thank you, that did it! |
You can have many series on a chart, such as a main series and a moving average series. Therefore, you need to ask the price for a specific instance of the series. |
I have a question regarding the reactive property. Aassuming that it's the equivalent to function handleIntervalSwitch(interval) {
seriesOptions.data = data2;
} but the chart position does not reset. The initial data is only a couple candles long do it does not fill the chart container, but the data set I switch to is, yet it ends where the original does and the chart area does not get filled. 83f457207d953d4d76f10cca6427910f.mp4EDIT: I managed to access the 'ITimeScaleApi' and used |
Could you please provide a minimal reproduction of the issue with reactive data. Also keep in mind that
or just this:
I have a demo where data is reactive. |
Hey again, I used your lib to create a sparkline with coingecko data and I'm experiencing a bug I'm not quite sure how to tackle. I have 3 items, and for each item, I render a card with its own sparkline. The problem is that more often than not, only the first one will render and the others will not until I switch to another route and then switch back. And then if I do it again, they will disappear again. Firefox.Developer.Edition.-.24.September.2022.mp4Here is a minimal reproduction repo: and here is the code
<script>
import { tokens } from '$lib/stores/tokens';
import TokenCard from '$lib/components/TokenCard.svelte';
import { isEmpty } from '$lib/utils/index';
</script>
<main class="h-screen bg-gray-100">
<div class="max-w-7xl flex items-center justify-center p-4 h-full gap-2">
{#if !isEmpty($tokens)}
{#each Object.values($tokens) as token}
{#if !isEmpty(token.coingecko_data || {})}
<TokenCard id={token.coingecko_data.id} prices={token.coingecko_data.prices} />
{/if}
{/each}
{/if}
</div>
</main>
<script>
import Sparkline from '$lib/components/Sparkline.svelte';
export let id, prices;
</script>
<div class="flex flex-col items-center gap-2 rounded-lg p-2 shadow-sm bg-white text-gray-600 text-xs">
{id}
<Sparkline data={prices} />
</div>
<script>
import { Chart, AreaSeries } from 'svelte-lightweight-charts';
import { formatCurrency } from '@coingecko/cryptoformat';
export let data;
let priceData = data.reverse().map(([time, value]) => ({ time, value }));
const chartOptions = {
height: 60,
width: 150,
layout: {
backgroundColor: 'rgba(255, 255, 255, 0)',
textColor: '#71717A'
},
grid: {
vertLines: {
visible: false
},
horzLines: {
visible: false
}
},
crosshair: {
mode: 0,
horzLine: {
visible: false
},
vertLine: {
visible: false
}
},
timeScale: {
rightOffset: 0,
borderVisible: false,
barSpacing: 5,
fixLeftEdge: true,
timeVisible: false,
visible: false
},
priceScale: {
borderVisible: false,
visible: false
},
rightPriceScale: {
visible: false
}
};
const seriesOptions = {
data: priceData,
reactive: true,
// lineColor: data[data.length - 1].value >= data[0].value ? '#57BD0D' : '#EE5465',
lineColor: '#5472cc',
lineWidth: 2,
topColor: 'rgba(255, 255, 255, 0)',
bottomColor: 'rgba(255, 255, 255, 0)',
priceLineVisible: false,
borderVisible: false
};
</script>
<Chart {...chartOptions}>
<AreaSeries {...seriesOptions} />
</Chart> Do you think you can please take a look and see what's causing it? |
Just replying again in case you didn't see my earlier comment |
Please create mocks for your data. Don't really want to go to unknown hosts. Check this line https://github.com/jakubdonovan/svelte-lightweight-charts-minimal/blob/coingecko-sparkline/src/lib/stores/tokens.js#L14 please. It looks like you never add new keys to an object. |
Do you have any information about the release date of 4.0 lightweight chart? |
I don't have this information. I hope it will happen this year. Support for 4.0 does not require much effort on my part and I will release a new version on the same day. |
Looks like this no longer works due to upstream changes. But I am also unable to find a replacement for it :/ |
It still works for me with the following versions:
Please provide minimal reproduction, or at least your |
|
Try using |
Still the same issue with |
You have the same version of |
I don't see vite in your dependencies. What version of vite do you have? Try using |
Tried deleting |
I double checked this. I removed Can you provide a demo with the issue? |
You can use |
If I restart my dev server, I get the error:
and if I then reload the page, no errors appear and the page loads.
EDIT: I added lightweight-charts and svelte-lightweight-charts to optimizeDeps and it works more often than not but i still sometimes get the error
How do I go about resolving this issue?
The text was updated successfully, but these errors were encountered: