Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5f222c7
fix(create-rspeedy): monorepo type error
Mori-Yang Apr 15, 2025
d57d5ff
Merge branch 'main' into main
Mori-Yang Apr 15, 2025
73945ff
feat(react):standalone namespace JSX
Mori-Yang Apr 16, 2025
95c595a
chore: import types
Mori-Yang Apr 16, 2025
d266103
Merge branch 'main' into main
Mori-Yang Apr 16, 2025
f2f7e42
Merge branch 'lynx-family:main' into main
Mori-Yang Apr 16, 2025
8e182eb
chore: remove ref types , WIP
Mori-Yang Apr 16, 2025
f9d273c
Merge branch 'main' of https://github.com/Mori-Yang/lynx-stack
Mori-Yang Apr 16, 2025
381b5ca
chore: add typecheck
Mori-Yang Apr 16, 2025
9d52ebd
Merge branch 'main' into main
Mori-Yang Apr 16, 2025
044353b
style: remove redundant imports
Mori-Yang Apr 16, 2025
6ddd58f
chore: export JSX
Mori-Yang Apr 16, 2025
751ebfd
Merge branch 'main' into main
Mori-Yang Apr 16, 2025
afcb436
chore: some text...
Mori-Yang Apr 16, 2025
357b7fd
Merge branch 'main' of https://github.com/Mori-Yang/lynx-stack
Mori-Yang Apr 16, 2025
306b051
fix: export JSX
Mori-Yang Apr 17, 2025
d7826dd
Merge branch 'main' into main
Mori-Yang Apr 17, 2025
31c5310
chore:add tscofnig and type tests
Mori-Yang Apr 17, 2025
4846f02
chore: check
Mori-Yang Apr 17, 2025
cf6e176
Merge branch 'main' of https://github.com/Mori-Yang/lynx-stack
Mori-Yang Apr 17, 2025
84d847d
Merge branch 'main' into main
colinaaa Apr 17, 2025
e689d0e
chore: modify tests
Mori-Yang Apr 17, 2025
41c5f9e
Merge branch 'main' of https://github.com/Mori-Yang/lynx-stack
Mori-Yang Apr 17, 2025
47e7e88
Merge branch 'main' into main
colinaaa Apr 17, 2025
8d22d9d
chore: modify tests
Mori-Yang Apr 17, 2025
d6405ec
Merge branch 'main' of https://github.com/Mori-Yang/lynx-stack
Mori-Yang Apr 17, 2025
b2f65e7
Create orange-days-chew.md
colinaaa Apr 17, 2025
af47ccc
Create stupid-hounds-reflect.md
colinaaa Apr 17, 2025
deff0b8
fix: exclude .test-d.* file when coverage test
Mori-Yang Apr 17, 2025
99f1eae
Merge branch 'main' of https://github.com/Mori-Yang/lynx-stack
Mori-Yang Apr 17, 2025
dae5e11
fix: .*
Mori-Yang Apr 17, 2025
65927c5
fix: eslint import order
colinaaa Apr 24, 2025
cd76e63
Merge remote-tracking branch 'upstream/main' into Mori-Yang/main
colinaaa Apr 24, 2025
d21f113
fix: change template of testing library
colinaaa Apr 24, 2025
9fbd518
ci: run tsc on test-publish
colinaaa Apr 24, 2025
c08de88
ci: remove tsc check
colinaaa Apr 24, 2025
aa26f1c
Merge remote-tracking branch 'upstream/main' into Mori-Yang/main
colinaaa Apr 24, 2025
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/orange-days-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"@lynx-js/react": patch
---

Support using `"jsx": "react-jsx"` along with `"jsxImportSource": "@lynx-js/react"` in `tsconfig.json`.

```json
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "@lynx-js/react"
}
}
```

This configuration enhances TypeScript definitions for standard JSX elements,
providing type errors for unsupported elements like `<div>` or `<button>`.
5 changes: 5 additions & 0 deletions .changeset/stupid-hounds-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-rspeedy": patch
---

Use `"jsx": "react-jsx"` with `"jsxImportSource": "@lynx-js/react"`.
9 changes: 9 additions & 0 deletions packages/react/runtime/__test__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../../../tsconfig.json",
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "@lynx-js/react",
"noEmit": true,
},
"include": ["**/*.ts", "**/*.tsx", "../../types/react.d.ts"],
}
104 changes: 104 additions & 0 deletions packages/react/runtime/__test__/typecheck/jsx-runtime.test-d.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright 2024 The Lynx Authors. All rights reserved.
Comment thread
Mori-Yang marked this conversation as resolved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
import type { JSX } from '../../jsx-runtime/index.js';
import type { MainThread, NodesRef, Target, TouchEvent } from '@lynx-js/types';
import { assertType, describe, test } from 'vitest';
import { useMainThreadRef } from '../../src/lynx-api.js';
import { useRef } from '../../src/hooks/react.js';

describe('JSX Runtime Types', () => {
test('should support basic JSX element', () => {
const viewEle = (
<view>
<text>child node</text>
</view>
);
assertType<JSX.Element>(viewEle);
});

test('should validate the required props for raw-text', () => {
// @ts-expect-error: Missing required prop 'text'
const shouldError = <raw-text></raw-text>;

const rawTextELe = <raw-text text={'text'}></raw-text>;
assertType<JSX.Element>(rawTextELe);
});

test('should support JSX.Elements', () => {
function App() {
function renderFoo(): JSX.Element {
return <text></text>;
}
return renderFoo();
}
assertType<JSX.Element>(App());
});

test('should error on unsupported tags', () => {
// @ts-expect-error: Unsupported tag
const divElement = <div></div>;
});

test('should support event handlers', () => {
const viewWithBind = (
<view
bindtap={(e) => {
assertType<number>(e.detail.x);
assertType<TouchEvent>(e);
}}
>
</view>
);
const viewWithCatch = (
<view
catchtap={(e) => {
assertType<Target>(e.currentTarget);
assertType<TouchEvent>(e);
}}
>
</view>
);
assertType<JSX.Element>(viewWithBind);
assertType<JSX.Element>(viewWithCatch);
});

test('should support main-thread event handlers', () => {
const viewWithMainThreadEvent = (
<view
main-thread:bindtap={(e) => {
assertType<number>(e.detail.x);
assertType<MainThread.Element>(e.currentTarget);
}}
>
</view>
);
assertType<JSX.Element>(viewWithMainThreadEvent);
});

test('should support ref prop with ref object', () => {
const ref = useRef<NodesRef>(null);
const viewWithRefObject = <view ref={ref}></view>;
assertType<JSX.Element>(viewWithRefObject);
});

test('should support ref prop with function', () => {
const ref = useRef<NodesRef>(null);
const viewWithRefCallback = (
<view
ref={(n) => {
assertType<NodesRef | null>(n);
ref.current = n;
}}
>
</view>
);
assertType<JSX.Element>(viewWithRefCallback);
});

test('should support main-thread ref', () => {
const mtRef = useMainThreadRef<MainThread.Element>(null);
const viewWithMainThreadRef = <view main-thread:ref={mtRef}></view>;
assertType<JSX.Element>(viewWithMainThreadRef);
});
});
Comment thread
Mori-Yang marked this conversation as resolved.
12 changes: 12 additions & 0 deletions packages/react/runtime/jsx-dev-runtime/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// Copyright 2024 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
import { JSX as _JSX } from 'react';

import { IntrinsicElements as _IntrinsicElements } from '@lynx-js/types';

export { jsxDEV, Fragment } from 'react/jsx-dev-runtime';
export { jsx, jsxs } from 'react/jsx-runtime';

export namespace JSX {
interface IntrinsicElements extends _IntrinsicElements {}

interface IntrinsicAttributes {}

type Element = _JSX.Element;
}
12 changes: 12 additions & 0 deletions packages/react/runtime/jsx-runtime/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
// Copyright 2024 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
import { JSX as _JSX } from 'react';

import { IntrinsicElements as _IntrinsicElements } from '@lynx-js/types';

export { jsx, jsxs, Fragment } from 'react/jsx-runtime';

export namespace JSX {
interface IntrinsicElements extends _IntrinsicElements {}

interface IntrinsicAttributes {}

type Element = _JSX.Element;
}
3 changes: 2 additions & 1 deletion packages/react/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"src"
],
"scripts": {
"test": "vitest run --coverage"
"test": "vitest run --coverage",
"test:type": "vitest --typecheck.only"
},
"devDependencies": {
"@lynx-js/react": "workspace:*",
Expand Down
3 changes: 2 additions & 1 deletion packages/react/runtime/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"outDir": "./lib",
"baseUrl": "./",
"rootDir": "./src",
"jsx": "preserve",
"jsx": "react-jsx",
"jsxImportSource": "./",
Comment thread
Mori-Yang marked this conversation as resolved.
},
"references": [{
"path": "../worklet-runtime/tsconfig.json",
Expand Down
1 change: 1 addition & 0 deletions packages/react/runtime/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export default defineConfig({

'__test__/page.test.jsx',
'**/*.d.ts',
'**/*.test-d.*',
],
thresholds: {
lines: 100,
Expand Down
2 changes: 2 additions & 0 deletions packages/react/types/react.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,5 @@ declare module '@lynx-js/types' {
'reuse-identifier'?: Key;
}
}

export type { JSX } from '../runtime/jsx-runtime/index.d.ts';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"jsx": "preserve",

"jsx": "react-jsx",
Comment thread
colinaaa marked this conversation as resolved.
"jsxImportSource": "@lynx-js/react",
"module": "node16",
"moduleResolution": "node16",

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"compilerOptions": {
"jsx": "preserve",
"jsx": "react-jsx",
"jsxImportSource": "@lynx-js/react",

"module": "node16",
"module": "node18",
"moduleResolution": "node16",

"strict": true,
Expand Down
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default defineConfig({
coverage: {
exclude: [
'**/*.d.ts',
'**/*.test-d.*',
'**/vitest.config.ts',
'**/rslib.config.ts',
'**/*.bench.js',
Expand Down
Loading