Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Svelte livepreview

default discord avatar
_nadiemlast year

Hi all,



I'm trying to create a svelte hook to use livepreview within my svelte app. I managed to get the subscription function to work, now every time when I update the page within Payload the mergedData logs to the console. This is working fine, somehow the mergedData contains the none-updated data, even when I'm updating the data and mergedData gets logged to the console it shows the none-updated data within the mergedData object. Clicking the save button within the CMS will update the data to the actual state.



I'm trying to figure out where the problem could be. This is my onChange function and subscription method.



const onChange = (mergedData) => {
        console.log(mergedData, 'mergedData');
        data.set(mergedData);
        isLoading.set(false);
    };

  const subscription = subscribe({
      callback: onChange,
      depth,
      initialData,
      serverURL
  });


payload version: 2.0.0


node: v19.9.0


Using the PostgresSQL connection



Fixed it, I was passing in the wrong server URL in the frontend. Should just be the payload server url. In my case:

http://localhost:3000
    Star on GitHub

    Star

    Chat on Discord

    Discord

    online

    Can't find what you're looking for?

    Get dedicated engineering support directly from the Payload team.