Skip to content

fix(lynx): defer the application first screen until the engine's __RenderPage lifecycle - #419

Merged
leonidaz merged 1 commit into
octanejs:mainfrom
Huxpro:fix/lynx-engine-deferred-first-screen
Jul 30, 2026
Merged

leonidaz merged 1 commit into
octanejs:mainfrom
Huxpro:fix/lynx-engine-deferred-first-screen

Conversation

@Huxpro

@Huxpro Huxpro commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add a firstScreenRender: 'engine' mode that defers the one-shot first-screen render until the engine's __RenderPage lifecycle arrives, and use it in the Rspeedy application entry. This fixes adopted first-screen trees painting with overflow: hidden semantics on native — most visibly, offscreen <image> content that never appeared when transformed onscreen.

Why

  • Native installs the decoded PageConfig on the ElementManager only after main-thread script evaluation: TemplateAssembler::LoadTemplateInternal runs VMExecute → DidVMExecute (→ OnPageConfigDecoded → ElementManager::SetConfig) → RenderTemplate (lynx-family/lynx, core/renderer/template_assembler.cc; the numbered pipeline comment sits right above LoadTemplateInternal). ElementManager::GetDefaultOverflowVisible() returns false while config_ is unset (core/renderer/dom/element_manager.h).
  • Octane's generated entry rendered the first screen during evaluation, so every element baked in the unconfigured defaults — defaultOverflowVisible above all — and the created platform UIs clipped their children permanently. ReactLynx never hits this because it builds elements inside the engine-invoked renderPage, after DidVMExecute.
  • On device (Lynx Explorer 3.9, iOS): the Product Detail (swiper) tutorial port translated a display: linear container with translateX, and every slide beyond the first rendered black — the subtree outside the container's own bounds was never displayed, and no later attribute/style/triggerLayout/element-replacement touch could recover it. A full main-thread PAPI call-sequence trace showed the adopted and background-mounted flows to be equivalent, isolating the divergence to evaluation-time element creation.

Changes

  • main-thread.ts: new validated firstScreenRender option (default immediate, preserving existing behavior for source and JavaScript-host tests). In engine mode the render is captured and released by the engine's __RenderPage lifecycle (or, as a fallback on hosts without the typed lifecycle, by the first background ready request — both prove evaluation has finished). markFirstScreenSyncReady no longer seals a window that is still waiting for the engine; an entry that finishes evaluation without rendering settles to skipped exactly as before. Unmount clears a pending deferred render.
  • first-screen.ts: the host/root render contract returns null when the render is deferred.
  • main-thread-entry.js (@octanejs/rspeedy-plugin): the generated application receiver opts into firstScreenRender: 'engine'.
  • first-screen.test.ts: regression driving the mode through a mock engine context — nothing paints during evaluation or on markFirstScreenSyncReady, and dispatching __RenderPage paints the tree and captures the first-tree snapshot.

Validation

  • vitest run --project lynx — 23 files, 264 tests passed
  • tsgo --noEmit for packages/lynx/tsconfig.json and tsconfig.testing.json
  • prettier --check on changed files
  • device evidence (Lynx Explorer 3.9, iOS simulator): the swiper tutorial port now paints every slide when translated onscreen, matching the ReactLynx original side-by-side, with a clean error console on a cold session; the gallery and bank-cards ports keep their previous behavior

Risk / follow-ups

  • immediate remains the default, so only the Rspeedy application graph changes behavior; all existing JS-host suites run unchanged.
  • In engine mode a host that never delivers __RenderPage and has no background falls back to never painting the first screen; the background-ready fallback covers every real transport we have.
  • Follow-up: the examples PR (feat(lynx): add Lynx tutorial example ports (gallery, bank-cards, swiper) #414) documents this as a known limitation in examples/swiper/README.md; that section should be updated to reference this fix once merged.

Note

Medium Risk
Changes first-screen timing for the Rspeedy application entry only (immediate stays default elsewhere), but incorrect release on unusual hosts could leave the first screen unpainted; core main-thread lifecycle and readiness paths are involved.

Overview
Adds firstScreenRender (immediate | engine, default immediate) so the one-shot main-thread first screen can wait until native PageConfig is on the ElementManager. In engine mode, root.render() queues work and returns null; the actual paint runs on __RenderPage (with a background main-ready fallback when that lifecycle is missing).

markFirstScreenSyncReady no longer closes the window while a deferred render is still pending; entries that finish evaluation without rendering still settle to skipped once release runs. Unmount clears any pending deferred render.

The Rspeedy main-thread-entry switches to firstScreenRender: 'engine', aligning first-screen element creation with ReactLynx-style timing and fixing cases where evaluation-time trees baked unconfigured overflow defaults (e.g. translated swiper slides painting black on device). Tests cover deferral through a mock engine context.

Reviewed by Cursor Bugbot for commit 1f317e1. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
octane-website Skipped Skipped Jul 30, 2026 1:18pm
octane-website-mcp Skipped Skipped Jul 30, 2026 1:18pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – octane-website-mcp July 30, 2026 13:18 Inactive
@vercel
vercel Bot temporarily deployed to Preview – octane-website July 30, 2026 13:18 Inactive
Huxpro added a commit to Huxpro/octane that referenced this pull request Jul 30, 2026
@leonidaz
leonidaz merged commit 91d206d into octanejs:main Jul 30, 2026
28 checks passed
leonidaz pushed a commit that referenced this pull request Jul 30, 2026
…per) (#414)

* feat(lynx): add tutorial example ports (gallery, bank-cards, swiper)

* docs(lynx-examples): the swiper first-screen clipping defect is fixed by #419

* lint

This branch was previously deployed

2 inactive deployments
Preview – octane-website-mcp — 1f317e1c Deployed Jul 30, 2026 by vercel[bot]
Preview – octane-website — 1f317e1c Deployed Jul 30, 2026 by vercel[bot]
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.

2 participants