Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/hungry-kids-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@remote-dom/react': minor
---

Add React 19 compatibility and update ref handling for cross-version support.
6 changes: 6 additions & 0 deletions packages/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @remote-dom/react

## Unreleased

### Patch Changes

- Add React 19 compatibility and update ref handling for cross-version support.

## 1.2.2

### Patch Changes
Expand Down
10 changes: 5 additions & 5 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@
},
"dependencies": {
"@remote-dom/core": "workspace:^1.7.0",
"@types/react": "^18.0.0",
"@types/react": "^18.0.0 || ^19.0.0",
"htm": "^3.1.1"
},
"peerDependencies": {
"react": "^17.0.0 || ^18.0.0"
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
},
"peerDependenciesMeta": {
"react": {
Expand All @@ -82,9 +82,9 @@
},
"devDependencies": {
"@quilted/react-testing": "^0.6.11",
"@types/react-dom": "^18.3.0",
"react": "^18.3.0",
"react-dom": "^18.3.0"
"@types/react-dom": "^19.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"browserslist": [
"defaults and not dead"
Expand Down
8 changes: 5 additions & 3 deletions packages/react/source/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ export function createRemoteComponent<
InstanceType<ElementConstructor>,
RemoteComponentPropsFromElementConstructor<ElementConstructor>
>(function RemoteComponent(props, ref) {
const internalRef = useRef<any>();
const lastRemotePropertiesRef = useRef<Record<string, any>>();
const internalRef = useRef<any>(undefined);
const lastRemotePropertiesRef = useRef<Record<string, any> | undefined>(
undefined,
);

const remoteProperties: Record<string, any> = {};
const children = toChildren(props.children);
Expand Down Expand Up @@ -195,7 +197,7 @@ export function createRemoteComponent<
{
ref: (refValue: any) => {
internalRef.current = refValue;
if (typeof ref === 'function') ref(refValue);
if (typeof ref === 'function') return ref(refValue);
else if (ref != null) ref.current = refValue;
},
},
Expand Down
21 changes: 11 additions & 10 deletions packages/react/source/host/component.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type {RemoteReceiverElement} from '@remote-dom/core/receivers';
import {
memo,
useRef,
useEffect,
type MutableRefObject,
type ComponentType,
} from 'react';
import {memo, useRef, useEffect, type ComponentType} from 'react';

// Compat type: mutable ref object that works across @types/react 17, 18, and 19.
// Matches runtime shape used by React refs in all supported versions.
// TODO: When React < 19 support is dropped, replace with `import { type RefObject } from 'react'`.
interface MutableRef<T> {
current: T;
}

import {useRemoteReceived} from './hooks/remote-received.ts';
import {
Expand Down Expand Up @@ -65,7 +66,7 @@ export interface RemoteComponentRendererOptions<Props = {}>

interface Internals extends Pick<RemoteComponentRendererProps, 'receiver'> {
id: string;
instanceRef: MutableRefObject<unknown>;
instanceRef: MutableRef<unknown>;
}

/**
Expand All @@ -85,7 +86,7 @@ export function createRemoteComponentRenderer<
receiver,
components,
}: RemoteComponentRendererProps) {
const internalsRef = useRef<Internals>();
const internalsRef = useRef<Internals | undefined>(undefined);

const attachedElement = useRemoteReceived(element, receiver);
const resolvedElement = attachedElement ?? element;
Expand Down Expand Up @@ -140,7 +141,7 @@ export function createRemoteComponentRenderer<

function createImplementationRef(
internals: Pick<Internals, 'id' | 'receiver'>,
): MutableRefObject<unknown> {
): MutableRef<unknown> {
let current: unknown = null;

return {
Expand Down
52 changes: 41 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading