hotwired / hotwired/hotwire-native-android

Unexpected behavior with `clear_all` and `replace_root`

Open
#115 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
163
Forks
37
PR merge metrics
No merged PRs in 30d

Description

I've noticed some behavior with clear_all and replace_root that I didn't expect.

Related Issues on the iOS side: https://github.com/hotwired/hotwire-native-ios/issues/107

Replace root

Steps to reproduce:
Ensure the Demo app has the following path configuration snippet (should be included by default):

{
  "patterns": [
     "^$",
     "^/$"
  ],
  "properties": {
     "presentation": "replace_root"
  }
},

Update the server.js file of the Demo Server like this:

app.get("/two", (request, response) => {
-  response.render("two", { title: "Push or Replace?", action: request.query.action })
+  response.redirect("/")
})
  1. Navigate to /one (title: "Navigate to another page")
  2. Navigate to /two (title: "Advance to another webpage")

Expected Server Logs:

GET /one
GET /two
GET /

Actual Server Logs:

GET /one
GET /two
GET /
GET /

The routing documentation states that replace_root will:

Dismiss if modal screen then
Pop to root then
Replace root screen on main stack

The root screen route is loaded twice.
This might be intended behavior, but my expectation was that the root screen would only be loaded once.

Clear all
  1. Add the following to the path configuration to use /two as a clear_all route:
{
  "patterns": [
    "^/two$"
  ],
  "properties": {
    "uri": "hotwire://fragment/web/home",
    "presentation": "clear_all"
  }
},
  1. Navigate to /one
  2. Navigate to /two

Expected Server Logs:

GET /one
GET /two
GET /

Actual Server Logs:

GET /one
GET /two

The documentation states that clear_all will:

Dismiss if modal screen then
Pop to root then
Refresh root screen on main stack

The app pops to the root but doesn’t reload the root screen.
I expected the root screen to reload after navigating to /two to refresh it. But maybe I misunderstood what "refresh" means in this context.

Note: In the related iOS issue I've described an unexpected behavior with Redirecting to a clear_all route.
This is not needed here because, on Android, redirecting to a clear_all route behaves the same as navigating to it, like above.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing both cases with the Demo Server change in server.js and the path configuration snippets, then compare the observed requests with the routing documentation. Trace the Android navigation behavior for replace_root and clear_all to determine whether the documented refresh semantics match the implementation. Done means resolving the behavior or clarifying and updating the documentation with confirmed expectations.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, kotlin
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.