Skip to content

Releases: razshare/sveltekit-sse

Fixing cleanup order of execution

06 Oct 08:51
Compare
Choose a tag to compare

Changes

  • Fixing an issue where when the client disconnects the produce::stop function would not trigger until produce::start finished.
    Which is problematic, because the order should be reversed: function produce::stop should run first, then produce::start, otherwise infinite emitters would never stop.

Fixing more type hints

04 Oct 17:06
Compare
Choose a tag to compare

Changes

  • source and source::select no longer accept generics T, instead source::select::json and source::select::transform will each accept separate generics.
    Meaning you will now type your values like so with source::select::json
    <!-- +page.svelte -->
    <script lang="ts">
      import { source } from 'sveltekit-sse'
    
      type User = {
        username: string
      }
    
      const user = 
        source('/my-event')
          .select('user')
            .json<User>()
    </script>
    
    {#if $user}
      <h3>{$user.username}</h3>
    {/if}
    And with source::select::transform
    <!-- +page.svelte -->
    <script lang="ts">
      import { source } from 'sveltekit-sse'
    
      type User = {
        username: string
      }
    
      // For the sake of brevity
      // let's suppose all the event emits 
      // is the raw name of the user
      function transformer(raw:string):User{
        return {
          username: raw
        }
      }
    
      const user = 
        source('/my-event')
          .select('user')
            .transform<User>(transformer)
    </script>
    
    {#if $user}
      <h3>{$user.username}</h3>
    {/if}

Fixing type hint for transform

24 Sep 16:37
Compare
Choose a tag to compare

Changes

  • source::select::transform is now correctly typed as returning Readable<T>

Exposing more types & renaming some

28 Jul 11:31
Compare
Choose a tag to compare

$\color{red}{\textsf{Breaking changes}}$

  • type ProduceOptions renamed to ProducePayload.
  • type EmitterOfManyEvents renamed to Emitter.

Changes

  • Exposing all types except internal ones.

Allowing custom http method names

27 Jul 10:26
Compare
Choose a tag to compare

Changes

  • It is now possible to set the http method of your source()
<!-- +page.svelte -->
<script>
  import { source } from 'sveltekit-sse'
  const connection = source('/issue-55/events', {
    options: {
      method: 'GET',  // The default is POST.
    },
  })
  const message = connection.select('message')
</script>

<h3>{$message}</h3>
import { produce } from 'sveltekit-sse'
import { delay } from '$lib/delay.js'

export async function GET() { // Then you can use GET here.
  return produce(async function start({ emit }) {
    while (true) {
      const { error } = emit('message', `${Date.now()}`)
      if (error) {
        return
      }
      await delay(1000)
    }
  })
}

More consistent source values

31 May 17:32
Compare
Choose a tag to compare

Changes

  • Previously, when using source('/some-path') you would always get a store with the first value initialized to blank.

    That doesn't make much sense if you're connecting to a source that had already open and had already produced some data.
    In that case, the returned store used to emit:
    1. First an undefined value
    2. And then the most recent value of the stream

      This change makes it so that the returned store emits directly the most recent value of the stream if available.
      For more details see #48

Fixing an issue with cache disabling

30 May 16:19
Compare
Choose a tag to compare

Changes

  • Fixed a bug where if you disabled connection caching and tried to source() twice at the same time on the same path, the second source would fail due to an internal aggressive semaphore.
    So in this case
    const sse1 = source('/events', { cache: false }).select('message');
    const sse2 = source('/events', { cache: false }).select('message');
    sse2 would fail to connect silently.

Dropping Beacons & Simplifying Api

11 May 12:42
Compare
Choose a tag to compare

$\color{red}{\textsf{Breaking changes}}$

  • Beacons are gone.
    Instead, disconnected clients are now detected through a server side ping mechanism.
    Unless you were manually configuring the beacon before - there's no need for any changes in userland, it should all just work.
    You can read more here.
  • The old events() functions has been replaced with a simpler produce() function which doesn't take the request and a whole object anymore, but just a start function instead (and some options as a second parameter).
    Something like this
    export async function POST() {
      return produce(conn => conn.emit('message', 'hello'))
    }
  • You can now write your logic within the body of your POST function without any worries or setup.
    Previously this was discouraged due to how beacons worked.
    This is now completely fine
    export function POST() {
      let counter = 0
      return produce(conn => {
        while(counter < 3){
          conn.emit("counter", `Counter is - ${counter}`)
          counter++
        }
      })
    }

Beacon variance & improved defaults

11 May 09:44
Compare
Choose a tag to compare

Changes

  • The source() function now also accepts a beaconVariance property.
    This property will vary the actual beacon request timing in order to avoid the thundering-herd effect.
    Defaults to 5 seconds.
    const connection = source(`/events`, {
        beacon: 15_000,
        beaconVariance: 4000
    })
  • The server side stream timeout is now 45 seconds by default (previously 7 seconds)
  • The client side beacon now triggers every 30 seconds by default (previously 5 seconds)
  • Fixed a memory leak which caused the internal timeouts map to keep growing.
    The map entries are now removed as clients disconnect, as it should have been from the beginning.

Fixing reconnect issues

10 May 23:47
Compare
Choose a tag to compare

Changes

  • Fixing an issue where source::close() and EventListener::connect() would not work as intended.
    Specifically EventListener::connect() would stop working after manually reconnecting through source::close()`.
    See #43

  • Adding more playwright tests