client icon indicating copy to clipboard operation
client copied to clipboard

Implement LS cleanup

Open BerkliumBirb opened this issue 1 year ago • 4 comments
trafficstars

In @logux/[email protected] localStorage may be clogged with old client identities.

view of dev tools with localStorage

image

Is there a way to clean up this?

BerkliumBirb avatar Oct 06 '24 17:10 BerkliumBirb

Seems like a bug. Can you post the full name of the key, what browser and how exactly do you use Logux (what log storage, how create Logux client).

ai avatar Oct 06 '24 17:10 ai

FF 130.

import { CrossTabClient, IndexedStore } from "@logux/client";
import { LocalPair } from "@logux/core";
import { nanoid } from "nanoid";

const pair = new LocalPair();

export const loguxClient = new CrossTabClient({
  store: new IndexedStore(),
  server: pair.left,
  subprotocol: "1.0.0",
  userId: nanoid(),
});

// Some loguxClient.type("...", ...) calls

loguxClient.start();
localStorage keys

image

BerkliumBirb avatar Oct 06 '24 17:10 BerkliumBirb

Got it. The problem is because you create unique user ID every time.

userId: nanoid(),

In this case you need to call client.destroy() to clean all data.

We can't add built-in feature because most of the users need opposite, the persistence local-first data with real user ID from database.

ai avatar Oct 06 '24 18:10 ai

I tried to use "stable" userId (saving it into localStorage), but it doesn't seem to solve the problem. Will report when have more info about it.

BerkliumBirb avatar Oct 07 '24 23:10 BerkliumBirb