Skip to content
Closed
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
8 changes: 8 additions & 0 deletions .changeset/tidy-buttons-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@lynx-js/react': minor
'@lynx-js/react-umd': minor
'@lynx-js/react-alias-rsbuild-plugin': minor
'@lynx-js/lynx-bundle-rslib-config': 'minor'
---

Export constants in `@lynx-js/react/constants`
1 change: 1 addition & 0 deletions packages/react-umd/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

export * as React from '@lynx-js/react';
export * as ReactInternal from '@lynx-js/react/internal';
export * as ReactConstants from '@lynx-js/react/constants';
export * as ReactJSXDevRuntime from '@lynx-js/react/jsx-dev-runtime';
export * as ReactJSXRuntime from '@lynx-js/react/jsx-runtime';
export * as ReactJSXLepusDevRuntime from '@lynx-js/react/lepus/jsx-dev-runtime';
Expand Down
8 changes: 8 additions & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
"types": "./runtime/lib/document.d.ts",
"default": "./runtime/lib/document.js"
},
"./constants": {
"types": "./runtime/lib/constants.d.ts",
"lazy": "./runtime/lazy/constants.js",
"default": "./runtime/lib/constants.js"
},
"./jsx-runtime": {
"types": "./runtime/jsx-runtime/index.d.ts",
"lazy": "./runtime/lazy/jsx-runtime.js",
Expand Down Expand Up @@ -121,6 +126,9 @@
"internal/document": [
"./runtime/lib/document.d.ts"
],
"constants": [
"./runtime/lib/constants.d.ts"
],
"jsx-runtime": [
"./runtime/jsx-runtime/index.d.ts"
],
Expand Down
14 changes: 14 additions & 0 deletions packages/react/runtime/__test__/lazy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as ReactExports from '../lazy/react.js';
import * as ReactCompatExports from '../lazy/compat.js';
import * as ReactLepusExports from '../lazy/react-lepus.js';
import * as ReactInternalExports from '../lazy/internal.js';
import * as ReactConstantsExports from '../lazy/constants.js';
import * as ReactJSXRuntimeExports from '../lazy/jsx-runtime.js';
import * as ReactJSXDevRuntimeExports from '../lazy/jsx-dev-runtime.js';
import * as ReactLegacyReactRuntimeExports from '../lazy/legacy-react-runtime.js';
Expand Down Expand Up @@ -62,6 +63,19 @@ describe('Lazy Exports', () => {
);
});

test('export APIs from "constants"', async () => {
const realAPIs = Object.assign(
{},
await import('@lynx-js/react/constants'),
);

expect(
new Set(Object.keys(ReactConstantsExports)),
).toStrictEqual(
new Set(Object.keys(realAPIs)),
);
});

test('export APIs from "jsx-runtime"', async () => {
const realAPIs = Object.assign(
{},
Expand Down
16 changes: 16 additions & 0 deletions packages/react/runtime/lazy/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +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 { sExportsReactConstants, target } from './target.js';

export const {
CHILDREN,
COMPONENT,
DIFF,
DIRTY,
DOM,
FLAGS,
INDEX,
PARENT,
} = target[sExportsReactConstants];
9 changes: 9 additions & 0 deletions packages/react/runtime/lazy/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as ReactAPIs from '@lynx-js/react';
import * as ReactCompatAPIS from '@lynx-js/react/compat';
import * as ReactInternal from '@lynx-js/react/internal';
import * as ReactConstants from '@lynx-js/react/constants';
import * as ReactJSXDevRuntime from '@lynx-js/react/jsx-dev-runtime';
import * as ReactJSXRuntime from '@lynx-js/react/jsx-runtime';
import * as ReactLegacyReactRuntime from '@lynx-js/react/legacy-react-runtime';
Expand All @@ -16,6 +17,7 @@ import {
sExportsReact,
sExportsReactCompat,
sExportsReactInternal,
sExportsReactConstants,
sExportsReactLepus,
target,
} from './target.js';
Expand Down Expand Up @@ -48,6 +50,13 @@ Object.defineProperty(target, sExportsReactInternal, {
configurable: true,
});

Object.defineProperty(target, sExportsReactConstants, {
value: ReactConstants,
enumerable: false,
writable: false,
configurable: true,
});

Object.defineProperty(target, sExportsJSXRuntime, {
value: ReactJSXRuntime,
enumerable: false,
Expand Down
8 changes: 0 additions & 8 deletions packages/react/runtime/lazy/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ import { sExportsReactInternal, target } from './target.js';

export const {
BackgroundSnapshotInstance,
CHILDREN,
COMPONENT,
Component,
DIFF,
DIRTY,
DOM,
FLAGS,
INDEX,
PARENT,
__ComponentIsPolyfill,
__DynamicPartChildren,
__DynamicPartChildren_0,
Expand Down
1 change: 1 addition & 0 deletions packages/react/runtime/lazy/target.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const sExportsReact = Symbol.for('__REACT_LYNX_EXPORTS__(@lynx-js/react)'
export const sExportsReactCompat = Symbol.for('__REACT_LYNX_EXPORTS__(@lynx-js/react/compat)');
export const sExportsReactLepus = Symbol.for('__REACT_LYNX_EXPORTS__(@lynx-js/react/lepus)');
export const sExportsReactInternal = Symbol.for('__REACT_LYNX_EXPORTS__(@lynx-js/react/internal)');
export const sExportsReactConstants = Symbol.for('__REACT_LYNX_EXPORTS__(@lynx-js/react/constants)');
export const sExportsJSXRuntime = Symbol.for('__REACT_LYNX_EXPORTS__(@lynx-js/react/jsx-runtime)');
export const sExportsJSXDevRuntime = Symbol.for('__REACT_LYNX_EXPORTS__(@lynx-js/react/jsx-dev-runtime)');
export const sExportsLegacyReactRuntime = Symbol.for('__REACT_LYNX_EXPORTS__(@lynx-js/react/legacy-react-runtime)');
3 changes: 2 additions & 1 deletion packages/react/runtime/lepus/jsx-runtime/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// 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 { CHILDREN, COMPONENT, DIFF, DIRTY, DOM, FLAGS, INDEX, PARENT, SnapshotInstance } from '@lynx-js/react/internal';
import { SnapshotInstance } from '@lynx-js/react/internal';
import { CHILDREN, COMPONENT, DIFF, DIRTY, DOM, FLAGS, INDEX, PARENT } from '@lynx-js/react/constants';

function createVNode(type, props, _key) {
if (typeof type === 'string') {
Expand Down
5 changes: 5 additions & 0 deletions packages/react/runtime/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright 2026 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 { CHILDREN, COMPONENT, DIFF, DIRTY, DOM, FLAGS, INDEX, PARENT } from './renderToOpcodes/constants.js';
2 changes: 0 additions & 2 deletions packages/react/runtime/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import { DynamicPartType } from './snapshot/dynamicPartType.js';
import { snapshotCreateList } from './snapshot/list.js';
import { SnapshotInstance, snapshotCreatorMap } from './snapshot/snapshot.js';

export { CHILDREN, COMPONENT, DIFF, DIRTY, DOM, FLAGS, INDEX, PARENT } from './renderToOpcodes/constants.js';

export { __page, __pageId, __root };

export {
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 @@ -64,6 +64,7 @@ export default defineConfig({
'@lynx-js/react/compat': path.resolve(__dirname, './compat/index.js'),
'@lynx-js/react/worklet-runtime/bindings': path.resolve(__dirname, './src/worklet-runtime/bindings/index.ts'),
'@lynx-js/react/runtime-components': path.resolve(__dirname, '../components/src/index.ts'),
'@lynx-js/react/constants': path.resolve(__dirname, './src/constants.ts'),
'@lynx-js/react/internal': path.resolve(__dirname, './src/internal.ts'),
'@lynx-js/react/jsx-dev-runtime': path.resolve(__dirname, './jsx-dev-runtime/index.js'),
'@lynx-js/react/jsx-runtime': path.resolve(__dirname, './jsx-runtime/index.js'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const reactLynxExternalsPreset: Externals = {
'react': ['ReactLynx', 'React'],
'@lynx-js/react': ['ReactLynx', 'React'],
'@lynx-js/react/internal': ['ReactLynx', 'ReactInternal'],
'@lynx-js/react/constants': ['ReactLynx', 'ReactConstants'],
'@lynx-js/react/jsx-dev-runtime': ['ReactLynx', 'ReactJSXDevRuntime'],
'@lynx-js/react/jsx-runtime': ['ReactLynx', 'ReactJSXRuntime'],
'@lynx-js/react/lepus/jsx-dev-runtime': [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ describe('pluginReactLynx', () => {
"@lynx-js/preact-devtools$": false,
"@lynx-js/react$": "<ROOT>/packages/react/runtime/lib/index.js",
"@lynx-js/react/compat$": "<ROOT>/packages/react/runtime/compat/index.js",
"@lynx-js/react/constants$": "<ROOT>/packages/react/runtime/lib/constants.js",
"@lynx-js/react/debug$": false,
"@lynx-js/react/experimental/lazy/import$": "<ROOT>/packages/react/runtime/lazy/import.js",
"@lynx-js/react/internal$": "<ROOT>/packages/react/runtime/lib/internal.js",
Expand Down
6 changes: 6 additions & 0 deletions packages/rspeedy/plugin-external-bundle/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ const reactLynxExternalTemplate = {
mainThread: { sectionPath: 'ReactLynx__main-thread' },
async: false,
},
'@lynx-js/react/constants': {
libraryName: ['ReactLynx', 'ReactConstants'],
background: { sectionPath: 'ReactLynx' },
mainThread: { sectionPath: 'ReactLynx__main-thread' },
async: false,
},
'@lynx-js/react/jsx-dev-runtime': {
libraryName: ['ReactLynx', 'ReactJSXDevRuntime'],
background: { sectionPath: 'ReactLynx' },
Expand Down
1 change: 1 addition & 0 deletions packages/rspeedy/plugin-react-alias/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export function pluginReactAlias(options: Options): RsbuildPlugin {
// 'debug',
'experimental/lazy/import',
'internal',
'constants',
'legacy-react-runtime',
'runtime-components',
'worklet-runtime/bindings',
Expand Down
32 changes: 32 additions & 0 deletions packages/rspeedy/plugin-react-alias/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ describe('React - alias', () => {
'@lynx-js/react/internal',
)

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

expect(config.resolve.alias).toHaveProperty(
'react$',
expect.stringContaining(
Expand All @@ -61,6 +65,13 @@ describe('React - alias', () => {
),
)

expect(config.resolve.alias).toHaveProperty(
'@lynx-js/react/constants$',
expect.stringContaining(
'/packages/react/runtime/lib/constants.js'.replaceAll('/', path.sep),
),
)

expect(config.resolve.alias).toHaveProperty(
'@lynx-js/react/experimental/lazy/import$',
expect.stringContaining(
Expand Down Expand Up @@ -211,6 +222,10 @@ describe('React - alias', () => {
'@lynx-js/react/internal',
)

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

expect(config.resolve.alias).toHaveProperty(
'react$',
expect.stringContaining(
Expand All @@ -232,6 +247,13 @@ describe('React - alias', () => {
),
)

expect(config.resolve.alias).toHaveProperty(
'@lynx-js/react/constants$',
expect.stringContaining(
'/packages/react/runtime/lib/constants.js'.replaceAll('/', path.sep),
),
)

expect(config.resolve.alias).toHaveProperty(
'@lynx-js/react/debug$',
false,
Expand Down Expand Up @@ -339,6 +361,16 @@ describe('React - alias', () => {
'/packages/react/runtime/lib/internal.js'.replaceAll('/', path.sep),
),
)

expect(webConfig.resolve.alias).toHaveProperty(
'@lynx-js/react/constants$',
expect.stringContaining(
'/packages/react/runtime/lib/constants.js'.replaceAll(
'/',
path.sep,
),
),
)
})

test('alias with plugins + environments', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/rspeedy/plugin-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"typia-rspack-plugin": "2.2.2"
},
"peerDependencies": {
"@lynx-js/react": "^0.103.0 || ^0.104.0 || ^0.105.0 || ^0.106.0 || ^0.107.0 || ^0.108.0 || ^0.109.0 || ^0.110.0 || ^0.111.0 || ^0.112.0 || ^0.113.0 || ^0.114.0 || ^0.115.0 || ^0.116.0 || ^0.117.0 || ^0.118.0"
"@lynx-js/react": "^0.103.0 || ^0.104.0 || ^0.105.0 || ^0.106.0 || ^0.107.0 || ^0.108.0 || ^0.109.0 || ^0.110.0 || ^0.111.0 || ^0.112.0 || ^0.113.0 || ^0.114.0 || ^0.115.0 || ^0.116.0 || ^0.117.0 || ^0.118.0 || ^0.119.0"
},
"peerDependenciesMeta": {
"@lynx-js/react": {
Expand Down
8 changes: 8 additions & 0 deletions packages/rspeedy/plugin-react/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ describe('Config', () => {
'@lynx-js/react/internal',
)

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

expect(config.resolve.alias).toHaveProperty(
'@lynx-js/react$',
expect.stringContaining(
Expand Down Expand Up @@ -284,6 +288,10 @@ describe('Config', () => {
'@lynx-js/react/internal',
)

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

expect(config.resolve.alias).toHaveProperty(
'@lynx-js/react$',
expect.stringContaining(
Expand Down
7 changes: 7 additions & 0 deletions packages/rspeedy/plugin-react/test/lazy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,17 @@ describe('Lazy', () => {
expect(config?.resolve?.alias).not.toHaveProperty(
'@lynx-js/react/internal',
)
expect(config?.resolve?.alias).not.toHaveProperty(
'@lynx-js/react/constants',
)
expect(config?.resolve?.alias).toHaveProperty(
'@lynx-js/react/internal$',
expect.stringContaining('lazy/internal'.replaceAll('/', path.sep)),
)
expect(config?.resolve?.alias).toHaveProperty(
'@lynx-js/react/constants$',
expect.stringContaining('lazy/constants'.replaceAll('/', path.sep)),
)
})

test('output.library', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const sExportsReactLepus = Symbol.for(
const sExportsReactInternal = Symbol.for(
'__REACT_LYNX_EXPORTS__(@lynx-js/react/internal)',
);
const sExportsReactConstants = Symbol.for(
'__REACT_LYNX_EXPORTS__(@lynx-js/react/constants)',
);
const sExportsJSXRuntime = Symbol.for(
'__REACT_LYNX_EXPORTS__(@lynx-js/react/jsx-runtime)',
);
Expand All @@ -24,13 +27,15 @@ it('should not have experimental/lazy/import imported', () => {
expect(lynx[sExportsReact]).toBeUndefined();
expect(lynx[sExportsReactLepus]).toBeUndefined();
expect(lynx[sExportsReactInternal]).toBeUndefined();
expect(lynx[sExportsReactConstants]).toBeUndefined();
expect(lynx[sExportsJSXRuntime]).toBeUndefined();
expect(lynx[sExportsJSXDevRuntime]).toBeUndefined();
expect(lynx[sExportsLegacyReactRuntime]).toBeUndefined();
} else {
expect(globalThis[sExportsReact]).toBeUndefined();
expect(globalThis[sExportsReactLepus]).toBeUndefined();
expect(globalThis[sExportsReactInternal]).toBeUndefined();
expect(globalThis[sExportsReactConstants]).toBeUndefined();
expect(globalThis[sExportsJSXRuntime]).toBeUndefined();
expect(globalThis[sExportsJSXDevRuntime]).toBeUndefined();
expect(globalThis[sExportsLegacyReactRuntime]).toBeUndefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const sExportsReactLepus = Symbol.for(
const sExportsReactInternal = Symbol.for(
'__REACT_LYNX_EXPORTS__(@lynx-js/react/internal)',
);
const sExportsReactConstants = Symbol.for(
'__REACT_LYNX_EXPORTS__(@lynx-js/react/constants)',
);
const sExportsJSXRuntime = Symbol.for(
'__REACT_LYNX_EXPORTS__(@lynx-js/react/jsx-runtime)',
);
Expand All @@ -30,13 +33,15 @@ it('should have experimental/lazy/import imported', async () => {
expect(lynx[sExportsReact]).not.toBeUndefined();
expect(lynx[sExportsReactLepus]).not.toBeUndefined();
expect(lynx[sExportsReactInternal]).not.toBeUndefined();
expect(lynx[sExportsReactConstants]).not.toBeUndefined();
expect(lynx[sExportsJSXRuntime]).not.toBeUndefined();
expect(lynx[sExportsJSXDevRuntime]).not.toBeUndefined();
expect(lynx[sExportsLegacyReactRuntime]).not.toBeUndefined();
} else {
expect(globalThis[sExportsReact]).not.toBeUndefined();
expect(globalThis[sExportsReactLepus]).not.toBeUndefined();
expect(globalThis[sExportsReactInternal]).not.toBeUndefined();
expect(globalThis[sExportsReactConstants]).not.toBeUndefined();
expect(globalThis[sExportsJSXRuntime]).not.toBeUndefined();
expect(globalThis[sExportsJSXDevRuntime]).not.toBeUndefined();
expect(globalThis[sExportsLegacyReactRuntime]).not.toBeUndefined();
Expand Down
Loading
Loading