@emeryld/rrroutes-client 2.6.2 → 2.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs
CHANGED
|
@@ -1652,6 +1652,16 @@ function arrayShallowEqual(a, b) {
|
|
|
1652
1652
|
function roomStateEqual(prev, next) {
|
|
1653
1653
|
return arrayShallowEqual(prev.rooms, next.rooms) && safeJsonKey(prev.joinMeta) === safeJsonKey(next.joinMeta) && safeJsonKey(prev.leaveMeta) === safeJsonKey(next.leaveMeta);
|
|
1654
1654
|
}
|
|
1655
|
+
function isSameObjectReference(prev, next) {
|
|
1656
|
+
if (prev !== next) return false;
|
|
1657
|
+
if (next == null) return false;
|
|
1658
|
+
const valueType = typeof next;
|
|
1659
|
+
return valueType === "object" || valueType === "function";
|
|
1660
|
+
}
|
|
1661
|
+
function shouldWarnSocketMutationGuard() {
|
|
1662
|
+
const nodeEnv = globalThis.process?.env?.NODE_ENV;
|
|
1663
|
+
return nodeEnv !== "production";
|
|
1664
|
+
}
|
|
1655
1665
|
function safeDescribeHookValue2(value) {
|
|
1656
1666
|
if (value == null) return value;
|
|
1657
1667
|
const valueType = typeof value;
|
|
@@ -1933,6 +1943,7 @@ function buildSocketedRoute(options) {
|
|
|
1933
1943
|
});
|
|
1934
1944
|
if (!client) return;
|
|
1935
1945
|
const queue = [];
|
|
1946
|
+
const sameRefWarnedEvents = /* @__PURE__ */ new Set();
|
|
1936
1947
|
let draining = false;
|
|
1937
1948
|
let active = true;
|
|
1938
1949
|
const drainQueue = () => {
|
|
@@ -1949,6 +1960,13 @@ function buildSocketedRoute(options) {
|
|
|
1949
1960
|
nextUpdate.payload,
|
|
1950
1961
|
nextUpdate.meta ? { ...nextUpdate.meta, args: useArgs } : { args: useArgs }
|
|
1951
1962
|
);
|
|
1963
|
+
if (next === null) return prev;
|
|
1964
|
+
if (shouldWarnSocketMutationGuard() && isSameObjectReference(prev, next) && !sameRefWarnedEvents.has(nextUpdate.event)) {
|
|
1965
|
+
sameRefWarnedEvents.add(nextUpdate.event);
|
|
1966
|
+
console.warn(
|
|
1967
|
+
`[socketedRoute] applySocket("${nextUpdate.event}") returned the previous reference. Return a new object/array for updates, or return null for no change.`
|
|
1968
|
+
);
|
|
1969
|
+
}
|
|
1952
1970
|
const nextRoomState = roomsFromData(
|
|
1953
1971
|
next,
|
|
1954
1972
|
toRooms
|
|
@@ -1972,6 +1990,7 @@ function buildSocketedRoute(options) {
|
|
|
1972
1990
|
const unsubscribes = entries.map(
|
|
1973
1991
|
([ev, fn]) => client.on(ev, (payload, meta) => {
|
|
1974
1992
|
queue.push({
|
|
1993
|
+
event: ev,
|
|
1975
1994
|
fn,
|
|
1976
1995
|
payload,
|
|
1977
1996
|
...meta ? { meta } : {}
|