appsmithorg / appsmith

Platform to build admin panels, internal tools, and dashboards. Integrates with 25+ databases and any API.
https://www.appsmith.com
Apache License 2.0
34.63k stars 3.74k forks source link

[Bug]: navigateTo() changes branches in edit mode #37080

Open eedwardsSGS opened 3 weeks ago

eedwardsSGS commented 3 weeks ago

Is there an existing issue for this?

Description

I am working on a branch other than master in Appsmith. I have a button that fires this function:

export default {
    edit: (orderAddress) => {
        navigateTo("Edit Batch", {
            breadcrumb: "Test Team",
            recipient: orderAddress.ship_to_recipient || "",
            line1: orderAddress.ship_to_address_line_1,
            line2: orderAddress.ship_to_address_line_2 || "",
            line3: orderAddress.ship_to_address_line_3 || "",
            city: orderAddress.ship_to_city,
            state: orderAddress.ship_to_state,
            zip: orderAddress.ship_to_zip,
            country: orderAddress.ship_to_country,
            batchId: orderAddress.batch_id
    })
    },
}

When I press it, it navigates to that page but then either immediately changes to the master branch and forgets all the queryParams, or displays the page correctly until I click on anything, at which point it changes to the master branch and forgets all the queryParams.

Steps To Reproduce

  1. Create an app
  2. Create two pages on the app
  3. Create a button with a function that changes from page 1 to page 2 and adds query params
  4. Create a text widget on page 2 that displays the query params
  5. Connect to github
  6. Create a second branch
  7. Change to that second branch
  8. Stay in edit mode
  9. Navigate to page 1
  10. Click on the button
  11. Look at page 2
  12. Click on page 2
  13. Look at page 2 again

Public Sample App

No response

Environment

Production

Severity

Medium (Frustrating UX)

Issue video log

No response

Version

Self Hosted - 1.41

eedwardsSGS commented 3 weeks ago

Something else may be going on here. Even if I'm in the master branch, it navigates to the page (in the correct branch, master) then if I click anywhere the page refreshes and it drops all the query params. This only occurs in edit mode, in the deployed version (and all changes have been deployed) this does not happen and everything works fine.

eedwardsSGS commented 3 weeks ago

It seems to be related to the newline character '%0A'. appsmith.URL.queryParams.recipient as far as I understand when I access it that way, Appsmith should have already decoded it and passed it as a string.

image

eedwardsSGS commented 3 weeks ago

On closer examination, it looks like Appsmith's getQueryParamsFromString needs to add newline escape characters replacing:

try {
    return JSON.parse(
      '{"' +
        decodeURI(search)
          .replace(/"/g, '\\"')
          .replace(/&/g, '","')
          .replace(/=/g, '":"') +
        '"}',
    );

with this:

try {
    return JSON.parse(
      '{"' +
        decodeURI(search)
          .replace(/"/g, '\\"')
          .replace(/&/g, '","')
          .replace(/=/g, '":"')
          .replace(/\n/g, '\\n') +
        '"}',
    );

Or similar.

AmanAgarwal041 commented 2 weeks ago

@eedwardsSGS The query params are not persisted on the url but {{appsmith.URL.queryParams}} persists the data. Is there any other use case that you are trying ?

https://github.com/user-attachments/assets/c8a7a8be-d8bb-4298-a531-252d6471b55b

eedwardsSGS commented 1 week ago

@AmanAgarwal041 I'm not seeing a newline character in your example queryparams. That's what is breaking it. See my comments later in the thread.