Skip to content

Commit

Permalink
remove react as peers; replace Date.now() with performance.now() in p…
Browse files Browse the repository at this point in the history
…rep to nextjs dynamic io
  • Loading branch information
julianbenegas committed Oct 24, 2024
1 parent 3219480 commit 9982eb3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
4 changes: 0 additions & 4 deletions packages/basehub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
"build:bin": "pnpm emit-dts && tsup --config tsup-bin.config.ts",
"build:client": "tsup --config tsup-client.config.ts"
},
"peerDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"dependencies": {
"@basehub/genql": "9.0.0-canary.5",
"@basehub/mutation-api-helpers": "2.0.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/basehub/src/react/pump/client-pump.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const clientCache = new Map<

const lastResponseHashCache = new Map<string, string>();

const DEDUPE_TIME_MS = 500;
const DEDUPE_TIME_MS = 32;

export const ClientPump = <Queries extends PumpQuery[]>({
children,
Expand Down Expand Up @@ -87,7 +87,7 @@ export const ClientPump = <Queries extends PumpQuery[]>({

if (clientCache.has(queryCacheKey)) {
const cached = clientCache.get(queryCacheKey)!;
if (Date.now() - cached.start < DEDUPE_TIME_MS) {
if (performance.now() - cached.start < DEDUPE_TIME_MS) {
const response = await cached.response;
if (!response) return null;
if (response.newPumpToken) {
Expand Down Expand Up @@ -144,7 +144,7 @@ export const ClientPump = <Queries extends PumpQuery[]>({

// we quickly set the cache (without awaiting)
clientCache.set(queryCacheKey, {
start: Date.now(),
start: performance.now(),
response: responsePromise,
});

Expand Down
6 changes: 3 additions & 3 deletions packages/basehub/src/react/pump/server-pump.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let pumpToken: string | null = null;
let spaceID: string | null = null;
let pusherData: ResponseCache["pusherData"] | null = null;

const DEDUPE_TIME_MS = 500;
const DEDUPE_TIME_MS = 32;

export type PumpProps<Queries extends Array<PumpQuery>> = {
children: (
Expand Down Expand Up @@ -98,7 +98,7 @@ export const Pump = async <Queries extends Array<PumpQuery>>({

if (cache.has(cacheKey)) {
const cached = cache.get(cacheKey)!;
if (Date.now() - cached.start < DEDUPE_TIME_MS) {
if (performance.now() - cached.start < DEDUPE_TIME_MS) {
data = (await cached.data) as any;
}
}
Expand Down Expand Up @@ -134,7 +134,7 @@ export const Pump = async <Queries extends Array<PumpQuery>>({
})
: basehub(basehubProps).query(singleQuery);
cache.set(cacheKey, {
start: Date.now(),
start: performance.now(),
data: dataPromise,
});
data = await dataPromise;
Expand Down

0 comments on commit 9982eb3

Please sign in to comment.