Skip to content

fix(web): detect SubFrame client size changes - #204

Open
shrinktofit wants to merge 1 commit into
cocos:v4.0.0from
shrinktofit:codex/resize-bug
Open

fix(web): detect SubFrame client size changes#204
shrinktofit wants to merge 1 commit into
cocos:v4.0.0from
shrinktofit:codex/resize-bug

Conversation

@shrinktofit

Copy link
Copy Markdown
Contributor

Re: #

Changelog

  • Fix Web/SubFrame resize detection when the effective frame size changes without an inline style change.

Root Cause

ScreenAdapter._updateContainer() detected resize events by comparing the inline width and height strings of the game frame and container. When a SubFrame uses stable values such as width: 100% and height: 100%, resizing its embedding viewport changes clientWidth and clientHeight while those inline style strings remain unchanged. As a result, screen.windowSize could reflect the new DOM size, but no window-resize event was emitted and dependent view/framebuffer state remained stale.

Reproduction

  1. Initialize the Web ScreenAdapter with a GameDiv whose inline width and height remain 100%.
  2. Resize the embedding viewport so the frame's effective client size changes, for example from 800x600 to 640x360.
  3. Observe that screenAdapter.windowSize reports the new size, but the window-resize event is not emitted.
  4. The view adaptation and framebuffer resize path therefore does not run.

Solution

Cache and compare the effective CSS window size after container layout is updated. When it changes, update the cache before emitting window-resize, and derive the event payload from the same CSS-size sample multiplied by the current device pixel ratio. This keeps the existing DPR-only, fullscreen, and orientation mechanisms unchanged and does not add a public API.

Testing

  • Added a black-box Web ScreenAdapter regression test covering a SubFrame whose client size changes while its inline styles stay unchanged.
  • Verified the resize event is emitted exactly once with the new physical size and is not repeated for an unchanged size.
  • node ./node_modules/jest/bin/jest.js tests/pal/screen-adapter.test.ts tests/core/view.test.ts --runInBand
  • node ./node_modules/typescript/bin/tsc --noEmit

Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

@shrinktofit

Copy link
Copy Markdown
Contributor Author

@cocos-robot run test cases

@github-actions

Copy link
Copy Markdown

Code Size Check Report

Wechat (WASM) Before After Diff
2D Empty (legacy pipeline) 1014446 bytes 1014446 bytes ✅ 0 bytes
2D All (legacy pipeline) 2681971 bytes 2681971 bytes ✅ 0 bytes
2D All (new pipeline) 2773763 bytes 2773763 bytes ✅ 0 bytes
(2D + 3D) All 10031072 bytes 10031072 bytes ✅ 0 bytes
Web (WASM + ASMJS) Before After Diff
(2D + 3D) All 16867485 bytes 16867224 bytes 👍 -261 bytes

Interface Check Report

This pull request does not change any public interfaces !

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.

1 participant