@dxos/web-context-react 0.8.4-main.d05673bc65 → 0.8.4-main.dd46787728

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/web-context-react",
3
- "version": "0.8.4-main.d05673bc65",
3
+ "version": "0.8.4-main.dd46787728",
4
4
  "description": "React integration with web context protocol",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -21,15 +21,12 @@
21
21
  }
22
22
  },
23
23
  "types": "dist/types/src/index.d.ts",
24
- "typesVersions": {
25
- "*": {}
26
- },
27
24
  "files": [
28
25
  "dist",
29
26
  "src"
30
27
  ],
31
28
  "dependencies": {
32
- "@dxos/web-context": "0.8.4-main.d05673bc65"
29
+ "@dxos/web-context": "0.8.4-main.dd46787728"
33
30
  },
34
31
  "devDependencies": {
35
32
  "@testing-library/react": "^16.3.0",
@@ -37,7 +34,7 @@
37
34
  "@types/react-dom": "~19.2.3",
38
35
  "react": "~19.2.3",
39
36
  "react-dom": "~19.2.3",
40
- "vitest": "3.2.4"
37
+ "vitest": "4.1.5"
41
38
  },
42
39
  "peerDependencies": {
43
40
  "react": "~19.2.3"
@@ -5,7 +5,7 @@
5
5
  // @vitest-environment jsdom
6
6
 
7
7
  import { act, cleanup, render, screen } from '@testing-library/react';
8
- import React from 'react';
8
+ import React, { ReactNode, useEffect, useRef, useState } from 'react';
9
9
  import { afterEach, describe, expect, test } from 'vitest';
10
10
 
11
11
  import { CONTEXT_REQUEST_EVENT, createContext } from '@dxos/web-context';
@@ -37,7 +37,7 @@ describe('useWebComponentContext', () => {
37
37
 
38
38
  test('consumes context from updates (subscription)', async () => {
39
39
  const Container = () => {
40
- const [val, setVal] = React.useState('initial');
40
+ const [val, setVal] = useState('initial');
41
41
  return (
42
42
  <>
43
43
  <button onClick={() => setVal('updated')}>Update</button>
@@ -59,9 +59,9 @@ describe('useWebComponentContext', () => {
59
59
  });
60
60
 
61
61
  test('consumes context from DOM parent (outside React tree)', () => {
62
- const Wrapper = ({ children }: { children: React.ReactNode }) => {
63
- const ref = React.useRef<HTMLDivElement>(null);
64
- React.useEffect(() => {
62
+ const Wrapper = ({ children }: { children: ReactNode }) => {
63
+ const ref = useRef<HTMLDivElement>(null);
64
+ useEffect(() => {
65
65
  const handler = (e: Event) => {
66
66
  const event = e as any;
67
67
  if (event.context === ctx) {
package/src/provider.tsx CHANGED
@@ -149,8 +149,12 @@ export const ContextProtocolProvider = <T extends UnknownContext>({
149
149
  const handleContextProviderEvent = useCallback(
150
150
  (e: Event) => {
151
151
  const event = e as ContextProviderEvent<UnknownContext>;
152
- if (event.context !== context) return;
153
- if (containerRef.current && event.contextTarget === containerRef.current) return;
152
+ if (event.context !== context) {
153
+ return;
154
+ }
155
+ if (containerRef.current && event.contextTarget === containerRef.current) {
156
+ return;
157
+ }
154
158
 
155
159
  const seen = new Set<ContextCallback<ContextType<T>>>();
156
160
  for (const ref of subscriptionRefs) {
@@ -161,9 +165,13 @@ export const ContextProtocolProvider = <T extends UnknownContext>({
161
165
  }
162
166
 
163
167
  const info = subscriptions.get(callback);
164
- if (!info) continue;
168
+ if (!info) {
169
+ continue;
170
+ }
165
171
 
166
- if (seen.has(callback)) continue;
172
+ if (seen.has(callback)) {
173
+ continue;
174
+ }
167
175
  seen.add(callback);
168
176
 
169
177
  info.consumerHost.dispatchEvent(
@@ -198,7 +206,9 @@ export const ContextProtocolProvider = <T extends UnknownContext>({
198
206
 
199
207
  useEffect(() => {
200
208
  const el = containerRef.current;
201
- if (!el) return;
209
+ if (!el) {
210
+ return;
211
+ }
202
212
 
203
213
  el.addEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);
204
214
  el.addEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);