Skip to content

Commit

Permalink
feat(rsc): rsc-cache-read (#11127)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Jul 31, 2024
1 parent c59c8e3 commit 969eb6e
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions packages/router/src/rsc/RscCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,20 @@ export class RscCache {
}
this.cache.delete(data.key)

this.sendToWebSocket('update', {
fullCache: Object.fromEntries(
Array.from(this.cache.entries()).map(
([location, elementThenable]) => [
location,
// @ts-expect-error hack to get the value of a Thenable
elementThenable.value,
],
),
),
})
this.sendUpdateToWebSocket()
} else if (data.id === 'rsc-cache-clear') {
this.cache.clear()
this.sendToWebSocket('update', { fullCache: {} })
} else if (data.id === 'rsc-cache-enable') {
console.log('RscCache::message::rsc-cache-enable')
this.isEnabled = true
this.sendUpdateToWebSocket()
} else if (data.id === 'rsc-cache-disable') {
console.log('RscCache::message::rsc-cache-disable')
this.isEnabled = false
} else if (data.id === 'rsc-cache-read') {
console.log('RscCache::message::rsc-cache-read')
this.sendUpdateToWebSocket()
}
}
})
Expand Down Expand Up @@ -117,4 +111,16 @@ export class RscCache {
console.error('WebSocket connection is closed.')
}
}

private sendUpdateToWebSocket() {
this.sendToWebSocket('update', {
fullCache: Object.fromEntries(
Array.from(this.cache.entries()).map(([location, elementThenable]) => [
location,
// @ts-expect-error hack to get the value of a Thenable
elementThenable.value,
]),
),
})
}
}

0 comments on commit 969eb6e

Please sign in to comment.