@dxos/web-context-react 0.8.4-main.59c2e9b → 0.8.4-main.60689f5b1c

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.59c2e9b",
3
+ "version": "0.8.4-main.60689f5b1c",
4
4
  "description": "React integration with web context protocol",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -8,7 +8,7 @@
8
8
  "type": "git",
9
9
  "url": "https://github.com/dxos/dxos"
10
10
  },
11
- "license": "MIT",
11
+ "license": "FSL-1.1-Apache-2.0",
12
12
  "author": "DXOS.org",
13
13
  "sideEffects": true,
14
14
  "type": "module",
@@ -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.59c2e9b"
29
+ "@dxos/web-context": "0.8.4-main.60689f5b1c"
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.6"
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(
@@ -175,11 +183,11 @@ export const ContextProtocolProvider = <T extends UnknownContext>({
175
183
  [context],
176
184
  );
177
185
 
178
- // Notify subscribers when value changes
186
+ // Notify subscribers when value changes.
179
187
  useEffect(() => {
180
188
  // Skip notification if value hasn't changed? React does this for us if we use dependencies correctly?
181
189
  // No, we need to imperatively call callbacks.
182
- // value constraint is in the dependency array
190
+ // value constraint is in the dependency array.
183
191
 
184
192
  for (const ref of subscriptionRefs) {
185
193
  const callback = ref.deref();
@@ -198,12 +206,14 @@ 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);
205
215
 
206
- // Announce provider
216
+ // Announce provider.
207
217
  el.dispatchEvent(new ContextProviderEvent(context, el));
208
218
 
209
219
  return () => {
@@ -215,7 +225,7 @@ export const ContextProtocolProvider = <T extends UnknownContext>({
215
225
 
216
226
  return (
217
227
  <ContextRequestHandlerContext.Provider value={handleRequest}>
218
- <div ref={containerRef} style={{ display: 'contents' }}>
228
+ <div className='contents' ref={containerRef}>
219
229
  {children}
220
230
  </div>
221
231
  </ContextRequestHandlerContext.Provider>