Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix no-unchecked-record-access for presence #23581

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/framework/presence/src/presenceDatastoreManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ function mergeGeneralDatastoreMessageContent(
for (const valueManagerKey of Object.keys(workspaceData)) {
for (const [clientSessionId, value] of objectEntries(workspaceData[valueManagerKey])) {
mergedData[valueManagerKey] ??= {};
const oldData = mergedData[valueManagerKey][clientSessionId];
mergedData[valueManagerKey][clientSessionId] = mergeValueDirectory(
const oldData = mergedData[valueManagerKey]?.[clientSessionId];
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
mergedData[valueManagerKey]![clientSessionId] = mergeValueDirectory(
Comment on lines 120 to +123
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clearly not problematic. Line 120 ensures that mergedData[valueManagerKey] is defined.
So ? is definitely not appropriate.
no-unchecked-record-access is already enabled for this package. Why are there new issues being reported? (If a change in rule pending, did it do better before. The code is correct; so, don't want to see anything flagged here.)

oldData,
value,
0, // local values do not need a time shift
Expand Down Expand Up @@ -397,7 +398,7 @@ export class PresenceDatastoreManagerImpl implements PresenceDatastoreManager {
} else {
// All broadcast state is kept even if not currently registered, unless a value
// notes itself to be ignored.
let workspaceDatastore = this.datastore[workspaceAddress];
let workspaceDatastore: ValueElementMap<PresenceStatesSchema> | undefined = this.datastore[workspaceAddress];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type of change does not work. We already need to undo all of the similar changes. See comments in other related PRs. Please do not add more.

if (workspaceDatastore === undefined) {
workspaceDatastore = this.datastore[workspaceAddress] = {};
if (!workspaceAddress.startsWith("system:")) {
Expand Down
8 changes: 5 additions & 3 deletions packages/framework/presence/src/presenceStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export function mergeValueDirectory<
}
}
for (const [key, value] of Object.entries(update.items)) {
const baseElement = mergeBase.items[key];
const baseElement: InternalTypes.ValueDirectory<T> | InternalTypes.ValueOptionalState<T> | undefined = mergeBase.items[key];
mergeBase.items[key] = mergeValueDirectory(baseElement, value, timeDelta);
}
return mergeBase;
Expand Down Expand Up @@ -281,7 +281,8 @@ class PresenceStatesImpl<TSchema extends PresenceStatesSchema>
if ("initialData" in newNodeData) {
const { value, allowableUpdateLatencyMs } = newNodeData.initialData;
datastore[key] ??= {};
datastore[key][clientSessionId] = value;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
datastore[key]![clientSessionId] = value;
newValues[key] = value;
if (allowableUpdateLatencyMs !== undefined) {
cumulativeAllowableUpdateLatencyMs =
Expand Down Expand Up @@ -370,7 +371,8 @@ class PresenceStatesImpl<TSchema extends PresenceStatesSchema>
} else {
this.datastore[key] = {};
}
this.datastore[key][this.runtime.clientSessionId] = value;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.datastore[key]![this.runtime.clientSessionId] = value;
this.runtime.localUpdate(
{ [key]: value },
{
Expand Down
Loading