@dxos/web-context-react 0.8.4-main.bc674ce → 0.8.4-main.bcb3aa67d6

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.bc674ce",
3
+ "version": "0.8.4-main.bcb3aa67d6",
4
4
  "description": "React integration with web context protocol",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -29,7 +29,7 @@
29
29
  "src"
30
30
  ],
31
31
  "dependencies": {
32
- "@dxos/web-context": "0.8.4-main.bc674ce"
32
+ "@dxos/web-context": "0.8.4-main.bcb3aa67d6"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@testing-library/react": "^16.3.0",
@@ -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
@@ -175,11 +175,11 @@ export const ContextProtocolProvider = <T extends UnknownContext>({
175
175
  [context],
176
176
  );
177
177
 
178
- // Notify subscribers when value changes
178
+ // Notify subscribers when value changes.
179
179
  useEffect(() => {
180
180
  // Skip notification if value hasn't changed? React does this for us if we use dependencies correctly?
181
181
  // No, we need to imperatively call callbacks.
182
- // value constraint is in the dependency array
182
+ // value constraint is in the dependency array.
183
183
 
184
184
  for (const ref of subscriptionRefs) {
185
185
  const callback = ref.deref();
@@ -203,7 +203,7 @@ export const ContextProtocolProvider = <T extends UnknownContext>({
203
203
  el.addEventListener(CONTEXT_REQUEST_EVENT, handleContextRequestEvent);
204
204
  el.addEventListener(CONTEXT_PROVIDER_EVENT, handleContextProviderEvent);
205
205
 
206
- // Announce provider
206
+ // Announce provider.
207
207
  el.dispatchEvent(new ContextProviderEvent(context, el));
208
208
 
209
209
  return () => {
@@ -215,7 +215,7 @@ export const ContextProtocolProvider = <T extends UnknownContext>({
215
215
 
216
216
  return (
217
217
  <ContextRequestHandlerContext.Provider value={handleRequest}>
218
- <div ref={containerRef} style={{ display: 'contents' }}>
218
+ <div role='none' className='contents' ref={containerRef}>
219
219
  {children}
220
220
  </div>
221
221
  </ContextRequestHandlerContext.Provider>