Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
17 changes: 17 additions & 0 deletions .changeset/feat-react-portal-patch-channel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"@lynx-js/react": patch
---

Add `createPortal` for rendering a subtree into a different ReactLynx element identified by a `NodesRef`.

```tsx
function App() {
const [host, setHost] = useState(null);
return (
<view>
<view ref={setHost} />
{host && createPortal(<text>hi</text>, host)}
</view>
);
}
```
1 change: 0 additions & 1 deletion packages/genui/a2ui-playground/lynx-src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ export function App() {
const [error, setError] = useState<string>('');
const [loading, setLoading] = useState<boolean>(false);

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
useEffect(() => {
let cancelled = false;

Expand Down
6 changes: 6 additions & 0 deletions packages/react/etc/react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { cloneElement } from 'react';
import { Component } from 'react';
import type { ComponentChild } from 'preact';
import type { ComponentClass } from 'react';
import type { Consumer } from 'react';
import { createContext } from 'react';
Expand All @@ -19,6 +20,7 @@ import { Fragment } from 'react';
import { isValidElement } from 'react';
import { lazy } from 'react';
import { memo } from 'react';
import type { NodesRef } from '@lynx-js/types';
import { PureComponent } from 'react';
import type { ReactNode } from 'react';
import type { RefObject } from 'react';
Expand All @@ -33,6 +35,7 @@ import { useReducer } from 'react';
import { useRef } from 'react';
import { useState } from 'react';
import { useSyncExternalStore } from 'react';
import type { VNode } from 'preact';

export { cloneElement }

Expand All @@ -42,6 +45,9 @@ export { createContext }

export { createElement }

// @public
export function createPortal(vnode: ComponentChild, container: NodesRef): VNode<any> | null;

export { createRef }

// @public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ describe('formatPatch', () => {
SnapshotOperation.SetAttributes,
2,
{ hidden: true },
SnapshotOperation.nodesRefInsertBefore,
'[react-ref-2-0]',
3,
undefined,
SnapshotOperation.nodesRefRemoveChild,
'[react-ref-2-0]',
3,
SnapshotOperation.DEV_ONLY_AddSnapshot,
'unique-1',
'snapshotCreator-val',
Expand All @@ -37,6 +44,17 @@ describe('formatPatch', () => {
{ op: 'RemoveChild', parentId: 1, childId: 2 },
{ op: 'SetAttribute', id: 2, dynamicPartIndex: 1, value: 'disabled' },
{ op: 'SetAttributes', id: 2, values: { hidden: true } },
{
op: 'nodesRefInsertBefore',
identifier: '[react-ref-2-0]',
childId: 3,
beforeId: undefined,
},
{
op: 'nodesRefRemoveChild',
identifier: '[react-ref-2-0]',
childId: 3,
},
{
op: 'DEV_ONLY_AddSnapshot',
uniqID: 'unique-1',
Expand Down
Loading
Loading