Skip to content

web: extract shared code into web-common.js - #961

Open
Fristender wants to merge 1 commit into
david-vanderson:mainfrom
Fristender:feat/web-common-refactor
Open

web: extract shared code into web-common.js#961
Fristender wants to merge 1 commit into
david-vanderson:mainfrom
Fristender:feat/web-common-refactor

Conversation

@Fristender

@Fristender Fristender commented Aug 16, 2026

Copy link
Copy Markdown

This refactor is the prerequisite for #962

Moves all code shared between the in-page backend (web.js) and the upcoming Worker backend into a new ES module web-common.js (~1060 lines): shaders, WebRenderer base class (GL setup, textures, render geometry, import-object builder), and event helpers (encodeModifiers, touchIndex, WheelHandler, HiddenInputManager, getTouchCoords, dvui_fetch). web.js shrinks from ~1300 to ~620 lines and now just holds the app-specific Dvui subclass.

Review guide

  • web-common.js:1-95 — shader sources + dvui_fetch, moved verbatim; check no drift vs. old web.js.
  • web-common.js:96-150 — string/UTF helpers and encodeModifiers/touchIndex.
  • web-common.js:400-550WebRenderer class; buildImports() — verify the import list is the union both backends need.
  • web-common.js:1050-1085 — default no-op host functions; web.js overrides the ones it implements.
  • web.js:5 — imports from ./web-common.js; web.js:58class Dvui extends WebRenderer. Everything below should be override-only; confirm no duplicated logic remains.
  • build.zig:1641-1642web-common.js added to install set for web-test/web-app.
  • Verify: zig build web-app still serves and renders identically (pure refactor, no behavior change intended).

@Fristender
Fristender marked this pull request as draft August 16, 2026 22:49
@Fristender
Fristender marked this pull request as ready for review August 17, 2026 06:06
@david-vanderson

Copy link
Copy Markdown
Owner

@Fristender please be patient, I will get to this but it might be a week or two.

@MichaelBelousov Can you read this PR description and tell me if splitting the js across multiple files might cause any problems?

@MichaelBelousov

Copy link
Copy Markdown
Collaborator

Ofc, will take a look later!

@MichaelBelousov

Copy link
Copy Markdown
Collaborator

@david-vanderson I can take over as reviewer for this if you are Ok with that

@david-vanderson

Copy link
Copy Markdown
Owner

@david-vanderson I can take over as reviewer for this if you are Ok with that

That would be amazing! This PR is not supposed to change any behavior, just a refactor.

@MichaelBelousov
MichaelBelousov self-requested a review August 21, 2026 02:03
@MichaelBelousov

MichaelBelousov commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Unrelated, @Didas-git it looks like #706 broke web.d.ts for some users (like myself). I didn't realize because I'm still behind on a version (and I don't always run the typecheck rn lol). The web.d.ts should contain the list of public functions from web.js. Why was the exported interface removed? I am a user of that interface.

On second thought, let's move discussion to that PR.

@MichaelBelousov

MichaelBelousov commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

before I do a complete review, @Fristender, do you have a strong reason that web-standalone can't just (at least initially) just import web.js and reuse exported shaders and etc?

I don't mind the refactor and I know you already put work into this, but I'd generally prefer we do invasive changes as progressively as possible. In this case, separate the HiddenInputManager and WheelHandler logic inside web.js before we move it to a separate web-common.js. Would you be ok with adding a third PR before this one that does that, so this is easier to review?

@MichaelBelousov

Copy link
Copy Markdown
Collaborator

FWIW I can review it in this state but I will be slow. It'll be faster if you split up your changes into more well-scoped PRs that make diffing as usable as possible. I know you already split it once, but it's valuable to do these things in chunks we can reason about.

@Fristender

Copy link
Copy Markdown
Author

before I do a complete review, @Fristender, do you have a strong reason that web-standalone can't just (at least initially) just import web.js and reuse exported shaders and etc?

The idea is to preserve web-app only implementation details inside web.js and move things that web-app and web-standalone could share into web-common.js. That way it's easier to differentiate between shared and web-app only implementations.

I don't mind the refactor and I know you already put work into this, but I'd generally prefer we do invasive changes as progressively as possible. In this case, separate the HiddenInputManager and WheelHandler logic inside web.js before we move it to a separate web-common.js. Would you be ok with adding a third PR before this one that does that, so this is easier to review?

I am okay with this, working on this now. Also, do you guys have some tests that verify every feature works? Doesn't have to be code, could be a series of steps and the expected behavior. That way I can verify the refactor doesn't have regressions to save time.

@MichaelBelousov

Copy link
Copy Markdown
Collaborator

Also, do you guys have some tests that verify every feature works? Doesn't have to be code, could be a series of steps and the expected behavior. That way I can verify the refactor doesn't have regressions to save time.

@david-vanderson can you comment? My understanding is there are only some zig tests and the demo window.

It would be cool @david-vanderson if we had a pixel comparison threshold test for several backends, but I'm sure there are a number of problems with that. Graphl does have something like that with a screen shot diff test gh action. I should open it up

@david-vanderson

Copy link
Copy Markdown
Owner

Also, do you guys have some tests that verify every feature works? Doesn't have to be code, could be a series of steps and the expected behavior. That way I can verify the refactor doesn't have regressions to save time.

@david-vanderson can you comment? My understanding is there are only some zig tests and the demo window.

That's correct. I've been hesitant to add too many tests given the high rate of feature changes, but that does seem to be slowing down, so maybe we are transitioning to a more test-friendly phase.

Usually I click through the demo as a smoke test. For the web, I do it both on a PC and then on a phone (more limited).

But I can totally do that - if you two can get the code in a shape that looks good I can do manual regression testing.

It would be cool @david-vanderson if we had a pixel comparison threshold test for several backends, but I'm sure there are a number of problems with that. Graphl does have something like that with a screen shot diff test gh action. I should open it up

We tried that at the very beginning of the testing infrastructure but couldn't figure out how to make it work. I still think there is some kind of way here - like limited widget-tree hashing for normal tests, and specialized pixel comparison tests for low level stuff. But unsure how to proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants