Skip to content

feat(web): use pure DOM API to implement Element PAPIs#334

Merged
PupilTong merged 1 commit intolynx-family:mainfrom
PupilTong:p/hw/refactor-main-thread-api-for-issue-51
Mar 25, 2025
Merged

feat(web): use pure DOM API to implement Element PAPIs#334
PupilTong merged 1 commit intolynx-family:mainfrom
PupilTong:p/hw/refactor-main-thread-api-for-issue-51

Conversation

@PupilTong
Copy link
Collaborator

@PupilTong PupilTong commented Mar 25, 2025

Note that the web-mainthread-apis releasing is temporarily disabled

  1. rewrite all element PAPIs impl. Now we use DOM.
  2. use our new package @lynx-js/offscreen-document to support the new Element PAPI implementation in a worker

#51

Summary

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@changeset-bot
Copy link

changeset-bot bot commented Mar 25, 2025

🦋 Changeset detected

Latest commit: f3d89f7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 25, 2025

CodSpeed Performance Report

Merging #334 will not alter performance

Comparing PupilTong:p/hw/refactor-main-thread-api-for-issue-51 (f3d89f7) with main (797cfe6)

Summary

✅ 1 untouched benchmarks

@codecov
Copy link

codecov bot commented Mar 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codecov
Copy link

codecov bot commented Mar 25, 2025

Bundle Report

Changes will increase total bundle size by 5.07kB (1.24%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
@lynx-js/web-explorer-web-array-push 413.1kB 5.07kB (1.24%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: @lynx-js/web-explorer-web-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
static/js/index.js -2 bytes 148.83kB -0.0%
static/js/async/33.js (New) 92.46kB 92.46kB 100.0% 🚀
static/js/async/93.js (New) 92.46kB 92.46kB 100.0% 🚀
static/js/async/217.js (Deleted) -89.92kB 0 bytes -100.0% 🗑️
static/js/async/436.js (Deleted) -89.92kB 0 bytes -100.0% 🗑️

colinaaa
colinaaa previously approved these changes Mar 25, 2025
**Note that the web-mainthread-apis releasing is temporarily disabled**

1. rewrite all element PAPIs impl. Now we use DOM.
2. use our new package `@lynx-js/offscreen-document` to support the new Element PAPI implementation in a worker
@PupilTong PupilTong force-pushed the p/hw/refactor-main-thread-api-for-issue-51 branch from 1122e24 to f3d89f7 Compare March 25, 2025 12:00
@PupilTong PupilTong requested review from colinaaa and Copilot March 25, 2025 13:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request updates the element PAPIs implementation on the web platform to use pure DOM APIs and integrates the new package (@lynx-js/offscreen-document) for worker support. Key changes include rewriting event, style, and attribute/property functions to operate on native HTMLElements instead of custom element types, revising runtime module loading and exposure service logic, and removing legacy offscreen document utilities.

Reviewed Changes

Copilot reviewed 20 out of 24 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/web-platform/web-constants/src/index.ts Added an export statement for types from the web-worker-rpc package
packages/web-platform/web-mainthread-apis/src/utils/createExposureService.ts Implements and revises exposure event handling using native DOM events
packages/web-platform/web-mainthread-apis/src/MainThreadRuntime.ts Updates runtime configuration and module loading with adjustments to error handling and new symbol definitions
packages/web-platform/web-mainthread-apis/src/elementAPI/* Rewrites functions to operate on native HTMLElements and removes legacy custom element APIs
packages/web-platform/offscreen-document/src/webworker/OffscreenDocument.ts Adjusts class inheritance to extend OffscreenNode instead of EventTarget
(Other files) Various refactors in event handling, style updating, DOM tree operations, and element creation have been performed to align with the new pure DOM API approach
Files not reviewed (4)
  • cspell.jsonc: Language not supported
  • packages/web-platform/web-mainthread-apis/package.json: Language not supported
  • packages/web-platform/web-mainthread-apis/tsconfig.json: Language not supported
  • packages/web-platform/web-tests/package.json: Language not supported
Comments suppressed due to low confidence (2)

packages/web-platform/web-mainthread-apis/src/MainThreadRuntime.ts:215

  • The empty catch block in __LoadLepusChunk may hide errors during module imports. Consider logging the error or handling it appropriately for debugging.
this.__LoadLepusChunk: (path) => { try { this.lynx.requireModule(path); return true; } catch { } return false; };

packages/web-platform/web-mainthread-apis/src/utils/createExposureService.ts:45

  • [nitpick] Using the literal interval value (1000 / 20) directly can reduce clarity. Consider defining a named constant for the interval rate to improve maintainability.
}, 1000 / 20);

@PupilTong PupilTong added this pull request to the merge queue Mar 25, 2025
@PupilTong PupilTong removed this pull request from the merge queue due to a manual request Mar 25, 2025
@PupilTong PupilTong added this pull request to the merge queue Mar 25, 2025
Merged via the queue into lynx-family:main with commit 2a8ddf3 Mar 25, 2025
20 checks passed
@PupilTong PupilTong deleted the p/hw/refactor-main-thread-api-for-issue-51 branch March 25, 2025 13:54
colinaaa referenced this pull request in colinaaa/lynx-stack Mar 26, 2025
**Note that the web-mainthread-apis releasing is temporarily disabled**

1. rewrite all element PAPIs impl. Now we use DOM.
2. use our new package `@lynx-js/offscreen-document` to support the new
Element PAPI implementation in a worker

#51

<!--
  Thank you for submitting a pull request!

We appreciate the time and effort you have invested in making these
changes. Please ensure that you provide enough information to allow
others to review your pull request.

Upon submission, your pull request will be automatically assigned with
reviewers.

If you want to learn more about contributing to this project, please
visit:
https://github.com/lynx-family/lynx-stack/blob/main/CONTRIBUTING.md.
-->

## Summary

<!-- Can you explain the reasoning behind implementing this change? What
problem or issue does this pull request resolve? -->

<!-- It would be helpful if you could provide any relevant context, such
as GitHub issues or related discussions. -->

## Checklist

<!--- Check and mark with an "x" -->

- [x] Tests updated (or not required).
- [ ] Documentation updated (or not required).
colinaaa pushed a commit that referenced this pull request Mar 31, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @lynx-js/web-constants@0.10.0

### Minor Changes

- feat: rewrite the main thread Element PAPIs
([#343](#343))

    In this commit we've rewritten the main thread apis.

    The most highlighted change is that

    -   Before this commit we send events directly to bts
- After this change, we send events to mts then send them to bts with
some data combined.

### Patch Changes

- feat: The onNapiModulesCall function of lynx-view provides the fourth
parameter: `lynxView`, which is the actual lynx-view DOM.
([#350](#350))

- fix: publicComponentEvent args order
([#401](#401))

- Updated dependencies
\[[`a521759`](a521759)]:
    -   @lynx-js/web-worker-rpc@0.10.0

## @lynx-js/web-core@0.10.0

### Minor Changes

- feat: rewrite the main thread Element PAPIs
([#343](#343))

    In this commit we've rewritten the main thread apis.

    The most highlighted change is that

    -   Before this commit we send events directly to bts
- After this change, we send events to mts then send them to bts with
some data combined.

### Patch Changes

- refactor: timing system
([#378](#378))

    Now we moved the timing system to the background thread.

- feat: support `defaultOverflowVisible` config
([#406](#406))

- fix(web): rsbuild will bundle 2 exactly same chunk for two same `new
Worker` stmt
([#372](#372))

    the bundle size will be optimized about 28.2KB

- fix: inline style will be removed for value number `0`
([#368](#368))

the inline style value could be incorrectly removed for number value
`0`;

    For example, `flex-shrink:0` may be ignored.

- feat: The onNapiModulesCall function of lynx-view provides the fourth
parameter: `lynxView`, which is the actual lynx-view DOM.
([#350](#350))

- fix: publicComponentEvent args order
([#401](#401))

- Updated dependencies
\[[`3a8dabd`](3a8dabd),
[`a521759`](a521759),
[`890c6c5`](890c6c5)]:
    -   @lynx-js/web-worker-runtime@0.10.0
    -   @lynx-js/web-constants@0.10.0
    -   @lynx-js/web-worker-rpc@0.10.0

## @lynx-js/web-mainthread-apis@0.10.0

### Minor Changes

- feat: rewrite the main thread Element PAPIs
([#343](#343))

    In this commit we've rewritten the main thread apis.

    The most highlighted change is that

    -   Before this commit we send events directly to bts
- After this change, we send events to mts then send them to bts with
some data combined.

### Patch Changes

- feat(web): use pure DOM API to implement Element PAPIs
([#334](#334))

    1.  rewrite all element PAPIs impl. Now we use DOM.
2. use our new package `@lynx-js/offscreen-document` to support the new
Element PAPI implementation in a worker

- fix: inline style will be removed for value number `0`
([#368](#368))

the inline style value could be incorrectly removed for number value
`0`;

    For example, `flex-shrink:0` may be ignored.

- fix: publicComponentEvent args order
([#401](#401))

- Updated dependencies
\[[`3a8dabd`](3a8dabd),
[`a521759`](a521759),
[`890c6c5`](890c6c5)]:
    -   @lynx-js/web-constants@0.10.0

## @lynx-js/web-worker-runtime@0.10.0

### Minor Changes

- feat: rewrite the main thread Element PAPIs
([#343](#343))

    In this commit we've rewritten the main thread apis.

    The most highlighted change is that

    -   Before this commit we send events directly to bts
- After this change, we send events to mts then send them to bts with
some data combined.

### Patch Changes

- Updated dependencies
\[[`2a8ddf3`](2a8ddf3),
[`3a8dabd`](3a8dabd),
[`878050a`](878050a),
[`a521759`](a521759),
[`890c6c5`](890c6c5)]:
    -   @lynx-js/web-mainthread-apis@0.10.0
    -   @lynx-js/web-constants@0.10.0
    -   @lynx-js/web-worker-rpc@0.10.0

## @lynx-js/react@0.106.2

### Patch Changes

- fix: prevent multiple firstScreen events when reloading before
`jsReady` ([#377](#377))

- Optimize the bundle size by eliminating unnecessary code when the lazy
bundle is not utilized.
([#284](#284))

## @lynx-js/rspeedy@0.8.7

### Patch Changes

- Support using `-debugids` in `output.sourceMap.js`.
([#342](#342))

See [Source Map Debug ID
Proposal](https://github.com/tc39/ecma426/blob/main/proposals/debug-id.md)
for more details.

- Use `chunkLoading: 'import-scripts'` for Web platform
([#352](#352))

- Support `output.distPath.*`.
([#366](#366))

See [Rsbuild - distPath](https://rsbuild.dev/config/output/dist-path)
for all available options.

- Support `performance.printFileSize`
([#336](#336))

    Whether to print the file sizes after production build.

## @lynx-js/react-rsbuild-plugin@0.9.4

### Patch Changes

- feat: add extractStr option to pluginReactLynx
([#391](#391))

- Convert background-only files from js to ts
([#346](#346))

- Updated dependencies
\[[`f849117`](f849117),
[`d730101`](d730101),
[`42217c2`](42217c2),
[`f03bd4a`](f03bd4a)]:
    -   @lynx-js/react-webpack-plugin@0.6.10
    -   @lynx-js/template-webpack-plugin@0.6.7
    -   @lynx-js/react-alias-rsbuild-plugin@0.9.4
    -   @lynx-js/react-refresh-webpack-plugin@0.3.2
    -   @lynx-js/css-extract-webpack-plugin@0.5.2
    -   @lynx-js/web-webpack-plugin@0.6.3

## @lynx-js/web-elements@0.5.2

### Patch Changes

- fix: When list with list-type: flow, scrolltoupper, scrolltolower were
specified, there was a blank block.
([#379](#379))

- fix: do not show scroll bar
([#406](#406))

## @lynx-js/web-worker-rpc@0.10.0

### Patch Changes

- feat: The onNapiModulesCall function of lynx-view provides the fourth
parameter: `lynxView`, which is the actual lynx-view DOM.
([#350](#350))

## @lynx-js/react-webpack-plugin@0.6.10

### Patch Changes

- feat: add extractStr option to pluginReactLynx
([#391](#391))

- Fix issue with lazy loading of bundles when source maps are enabled.
([#380](#380))

- Fix issue where loading a lazy bundle fails if it does not return a
webpack chunk.
([#365](#365))

## @lynx-js/template-webpack-plugin@0.6.7

### Patch Changes

- fix: merge different chunk groups for same output filename
([#371](#371))

## create-rspeedy@0.8.7



## @lynx-js/react-alias-rsbuild-plugin@0.9.4



## upgrade-rspeedy@0.8.7

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants