Skip to content

test: Cover View beforeUpdate/afterUpdate transaction semantics - #1513

Open
mrousavy wants to merge 2 commits into
mainfrom
test/view-before-after-update-transactions
Open

test: Cover View beforeUpdate/afterUpdate transaction semantics#1513
mrousavy wants to merge 2 commits into
mainfrom
test/view-before-after-update-transactions

Conversation

@mrousavy

Copy link
Copy Markdown
Owner

Summary

  • TestView now counts beforeUpdate()/afterUpdate() invocations (getBeforeUpdateCount()/getAfterUpdateCount()), keeping all existing required props required
  • a new Harness test asserts the pair brackets exactly the transactions that deliver at least one Nitro prop:
    • a mount with zero provided Nitro props (TS-suppressed, runtime-legal for plain-JS consumers) is not a props transaction
    • a style-only resize with identical Nitro props is not a props transaction
    • a changed Nitro prop is exactly one transaction

Why

#1510 gates iOS prop delivery on hasAnyProvidedProps() / hasSameProps(), so beforeUpdate()/afterUpdate() only fire when a transaction actually delivers Nitro props - matching their doc contract ("Called right before updating props. React props are updated in a single batch/transaction.").

Android's generated ViewManager.updateState() still calls beforeUpdate()/afterUpdate() unconditionally on every state update, including zero-prop mounts and style-only rerenders. That platform asymmetry was previously invisible because no fixture counted these calls.

Expected CI status

🔴 This test is intentionally red on Harness Android until the Kotlin/JNI updater gates the calls the same way iOS does (e.g. by moving the beforeUpdate/afterUpdate calls into C++ behind the same provided/changed checks). iOS behavior already matches the asserted contract.

Validation

  • workspace typecheck (all packages)
  • eslint (example + react-native-nitro-test, CI settings)
  • swift-format + kotlin-format (no changes)
  • deterministic Nitrogen generation

🤖 Generated with Claude Code

TestView now counts beforeUpdate()/afterUpdate() invocations, and a new
Harness test asserts they bracket exactly the transactions that deliver
at least one Nitro prop:

- a mount with zero provided Nitro props is not a props transaction
- a style-only resize is not a props transaction
- a changed Nitro prop is exactly one transaction

iOS already behaves this way (hasTransactionPropChanges gate). Android
currently calls beforeUpdate()/afterUpdate() unconditionally on every
updateState(), so this test is expected to be red on the Android Harness
until the Kotlin ViewManager gates the calls the same way.
@vercel

vercel Bot commented Aug 20, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
nitro-docs Skipped Skipped Aug 20, 2026 2:19pm

Request Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c45d77269

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +454 to +455
expect(view.getBeforeUpdateCount()).toBe(1)
expect(view.getAfterUpdateCount()).toBe(1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep the Android harness suite passing

On Android, the initial zero-prop mount and the following rerender both pass through HybridTestViewManager.updateState(), which unconditionally invokes beforeUpdate() and afterUpdate() at lines 57–59. Consequently, when this assertion runs the counters are already 2 rather than 1, so the Harness Android job that executes this test via .github/workflows/harness-android.yml will fail on every run. Gate the Android lifecycle calls before landing this assertion, or make the test reflect the behavior supported by each platform.

Useful? React with 👍 / 👎.

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