rdkcentral / Lightning-SDK

SDK for Lightning framework
Apache License 2.0
130 stars 69 forks source link

[Router] backtrack functionality is not working as expected #385

Closed Gopal-moyya closed 1 year ago

Gopal-moyya commented 1 year ago

GIVEN the lightning application WHEN the router configured with backtrack as true AND enters your App via a deeplink THEN clicking on the handle back and observe the behaviour

Actual behaviour: The application is either closing or showing an exit dialog if the app has Expected behaviour: The application should recursively remove the last part of the has until it finds a valid path to navigate. In case there is no valid hash then it should exit the application.

Identified the issue at the below line, https://github.com/rdkcentral/Lightning-SDK/blob/master/src/Router/index.js#:~:text=if%20(level%20%3E%20history.length)%20%7B

This should change like the below,

`export const step = (level = 0) => { if (!level || isNaN(level)) { return false } const history = getHistory() // for now we only support negative numbers level = Math.abs(level)

//Check whether we have any history avaialble or not if (history.length) { // for now we only support history back const route = history.splice(history.length - level, level)[0] // store changed history setHistory(history) return navigate( route.hash, {

    [symbols.historyState]: route.state,
  },
  false
)

} else if (routerConfig.get('backtrack')) { const hashLastPart = /(\/:?[\w%\s-]+)$/ let hash = stripRegex(getHash()) let floor = getFloor(hash)

// test if we got deep-linked
if (floor > 1) {
  while (floor--) {
    // strip of last part
    hash = hash.replace(hashLastPart, '')
    // if we have a configured route
    // we navigate to it
    if (getRouteByHash(hash)) {
      return navigate(hash, { [symbols.backtrack]: true }, false)
    }
  }
}

}

// we can't step back past the amount // of history entries if (level > history.length) { if (isFunction(app._handleAppClose)) { return app._handleAppClose() } return app.application.closeApp() } return false }`

cc: @sandeep-vedam

ricardo-a-alves-alb commented 1 year ago

You should provide a PR to be analysed and tested properly.

uguraslan commented 1 year ago

Hey @Gopal-moyya, thanks for bringing this issue to our attention. It would be really helpful if you could provide us with a sample code or create a sample application using our Lightning playground to demonstrate the issue you're facing. This will allow us to better understand the context and reproduce the problem on our end.

Regarding the code snippet you've shared as a potential fix, can you please submit a pull request with the proposed changes. This will enable our team to properly review, test, and discuss the solution in a structured manner.

Gopal-moyya commented 1 year ago

Thanks, @uguraslan for a quick response.

You can reproduce this issue with the existing router app by updating it to the latest SDK https://github.com/mlapps/router-example-app, we also need to update the settings.json file with the backtrack value as true.

Please let me know if you need any other details regarding the issue.

sandeep-vedam commented 1 year ago

Hi @Gopal-moyya ,

Thanks for reporting issue. We could reproduce this issue using the router app with latest SDK. We will check the fix you have provided and proceed accordingly.

Thanks, Sandeep