Simplify getDeviceSpec and navigator test cleanup#27010
Conversation
- Remove null/undefined navigator guards from getDeviceSpec() since navigator is always present in Node 22+ and browsers. - Add comments on behavior differences between Node and browsers (deviceMemory is browser-only, hardwareConcurrency is available in both). - Remove null/undefined navigator test cases since no supported environment has a missing navigator. - Add Node-native navigator test case verifying hardwareConcurrency is set and deviceMemory is undefined. - Simplify restoreNavigator by removing the delete branch (Node 22+ always provides a navigator descriptor to restore). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Simplifies getDeviceSpec() and related tests under the assumption that Node 22+ is the supported runtime and navigator is always present.
Changes:
- Simplifies
getDeviceSpec()by removing the runtime guard/try-catch and using a typed cast fordeviceMemory. - Updates hardware stats tests to remove null/undefined navigator scenarios and add a Node-native navigator case.
- Simplifies navigator test restoration logic by always restoring the original property descriptor.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/runtime/container-runtime/src/containerRuntime.ts | Removes guard/try-catch around navigator access and uses typed intersection for deviceMemory. |
| packages/runtime/container-runtime/src/test/hardwareStats.spec.ts | Updates navigator mocking/restoration and modernizes test cases for Node 22 behavior. |
There was a problem hiding this comment.
Where do we document to customers that Node 22+ is required to use FF client?
Is there any enforcement via package management?
There was a problem hiding this comment.
Ah, I forgot to update the readmes 🤦♂️ the main one is https://github.com/microsoft/FluidFramework/blob/main/ClientRequirements.md but the template gets pasted in every README. I've opened #27039 to update the readmes.
There was a problem hiding this comment.
Okay - lets hold this breaking change until at least 2.100.
Please do also add a breaking change changeset. This is one of those rare cases where we can make a breaking change without a major. ... If we want to do yearly majors as recently discussed, then April might be the time to do so each year and include the Node requirement.
There was a problem hiding this comment.
Good to proceed now that 2.100 is the active window.
Please do add changeset highlighting Node22 requirement - should be a general all packages note.
There was a problem hiding this comment.
Opened #27116 for the all-packages breaking change notice and also ensuring the engines field is correct for all workspaces. For this PR, the latest iteration has an additional specific changeset detailing the impact of this navigator dependency.
Wraps the descriptor capture in an IIFE so the assert narrows the type to a definite PropertyDescriptor, eliminating the non-null assertion and eslint disable in restoreNavigator. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
🔭 PR Review Fleet ReportNote This report is generated by an experimental AI review fleet and is provided as a beta feature. Findings are a starting point for discussion, not a gate. Use your own judgement. Verdict: ❌ Request Changes 0 Exterminate, 1 Squash, 0 Investigate Findings
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Description
Now that we require Node 22 (#26934),
navigatoris always available (in both browsersand Node 22). This simplifies
getDeviceSpec()and its tests:typeof navigator === "object"guard and try/catch fromgetDeviceSpec()since navigator is always present in supported environments.
as anycast fordeviceMemorywith a typed intersection cast(
Navigator & { deviceMemory?: number }), eliminating three eslint disables.nullandundefinednavigator test cases since no supported environmenthas a missing navigator.
hardwareConcurrencyis a numberand
deviceMemoryis undefined (matching Node 22's built-in navigator behavior).restoreNavigatorby removing thedeletebranch (Node 22 always providesa navigator descriptor to restore).
These improvements were identified during review of #26938.
AB#68707
Reviewer Guidance
The review process is outlined on this wiki page.