Skip to content
Merged
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/cruel-rocks-open.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-rspeedy": patch
---

Add `import '@lynx-js/react/debug'` for all templates.
18 changes: 18 additions & 0 deletions .changeset/smooth-bars-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"@lynx-js/react": patch
---

Introduce `@lynx-js/react/debug` which would include debugging warnings and error messages for common mistakes found.

Add the import to `@lynx-js/react/debug` at the first line of the entry:

```js
import '@lynx-js/react/debug';
import { root } from '@lynx-js/react';

import { App } from './App.jsx';

root.render(
<App />,
);
```
5 changes: 5 additions & 0 deletions .changeset/spicy-seas-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/react-alias-rsbuild-plugin": patch
---

Support `@lynx-js/react/debug`.
1 change: 1 addition & 0 deletions examples/react/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@lynx-js/react/debug';
import { root } from '@lynx-js/react';

import { App } from './App.jsx';
Expand Down
5 changes: 5 additions & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"lazy": "./runtime/lazy/react.js",
"default": "./runtime/lib/index.js"
},
"./debug": {
"types": "./runtime/debug/index.d.ts",
"lazy": "./runtime/debug/index.js",
"default": "./runtime/debug/index.js"
},
"./experimental/lazy/import": {
"types": "./runtime/lazy/import.d.ts",
"default": "./runtime/lazy/import.js"
Expand Down
4 changes: 2 additions & 2 deletions packages/react/runtime/.npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*
!debug/*
!debug/**
!jsx-dev-runtime/*
!jsx-runtime/*
!lazy/*
Expand All @@ -7,5 +9,3 @@
!lepus/*
!lib/**
!lib/*
!src/**
!src/*
8 changes: 8 additions & 0 deletions packages/react/runtime/debug/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2025 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.

if (process.env.NODE_ENV === 'development') {
// eslint-disable-next-line n/no-extraneous-require
require('preact/debug');
}
4 changes: 4 additions & 0 deletions packages/react/runtime/debug/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright 2025 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.
export {};
5 changes: 5 additions & 0 deletions packages/react/runtime/debug/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright 2025 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 './index.cjs';
1 change: 1 addition & 0 deletions packages/react/runtime/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"path": "../worklet-runtime/tsconfig.json",
}],
"include": [
"debug",
"jsx-dev-runtime",
"jsx-runtime",
"lepus",
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 @@ -74,6 +74,7 @@ export default defineConfig({
name: 'react/runtime',
coverage: {
exclude: [
'debug',
'jsx-runtime',
'jsx-dev-runtime',
'lepus/jsx-dev-runtime',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@lynx-js/react/debug'
import { root } from '@lynx-js/react'

import { App } from './App.jsx'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@lynx-js/react/debug'
import { root } from '@lynx-js/react'

import { App } from './App.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@lynx-js/react/debug'
import { root } from '@lynx-js/react'

import { App } from './App.jsx'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@lynx-js/react/debug'
import { root } from '@lynx-js/react'

import { App } from './App.jsx'
Expand Down
8 changes: 7 additions & 1 deletion packages/rspeedy/plugin-react-alias/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function pluginReactAlias(options: Options): RsbuildPlugin {
})
})

api.modifyBundlerChain(async chain => {
api.modifyBundlerChain(async (chain, { isProd }) => {
const [
jsxRuntimeBackground,
jsxRuntimeMainThread,
Expand Down Expand Up @@ -117,6 +117,8 @@ export function pluginReactAlias(options: Options): RsbuildPlugin {
// react-transform may add imports of the following entries
// We need to add aliases for that
const transformedEntries = [
// TODO: add `debug` after bump peerDependencies['@lynx-js/react'] to 0.111.1
// 'debug',
'experimental/lazy/import',
'internal',
'legacy-react-runtime',
Expand All @@ -137,6 +139,10 @@ export function pluginReactAlias(options: Options): RsbuildPlugin {
),
)

if (isProd) {
chain.resolve.alias.set('@lynx-js/react/debug$', false)
}

chain
.resolve
.alias
Expand Down
9 changes: 9 additions & 0 deletions packages/rspeedy/plugin-react-alias/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ describe('React - alias', () => {
),
)

expect(config.resolve.alias).not.toHaveProperty(
'@lynx-js/react/debug$',
)

expect(config.resolve.alias).toHaveProperty(
'preact$',
expect.stringContaining(
Expand Down Expand Up @@ -194,6 +198,11 @@ describe('React - alias', () => {
'/packages/react/runtime/lib/internal.js'.replaceAll('/', path.sep),
),
)

expect(config.resolve.alias).toHaveProperty(
'@lynx-js/react/debug$',
false,
)
})

test('alias once', async () => {
Expand Down
Loading