Skip to content

Conversation

@sachitv
Copy link
Contributor

@sachitv sachitv commented Mar 4, 2021

This fixes #2887.

@sachitv sachitv requested a review from a team March 4, 2021 04:49
Copy link
Collaborator

@vdonato vdonato left a comment

Choose a reason for hiding this comment

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

Hi @sachitv, thanks so much for your contribution!

The general approach to this fix is correct, but there are a few details that I think need to be ironed out before this can be merged. Please see my comments below.

Additionally, it'd be great if you could add some unit tests for the handlePageInfoChanged method to App.test.tsx to make it less likely that a regression causes this issue to happen again. The tests should be added into a new App.handlePageInfoChanged describe block and will likely be structurally similar to the existing App.handleNewReport tests. We'll want to check four cases:

  1. / pathname with no query string
  2. / pathname with a query string
  3. non-/ pathname with no query string
  4. non-/ pathname with a query string

Feel free to ask me if you happen to have any questions about adding tests!

Comment on lines 379 to 382
Copy link
Collaborator

Choose a reason for hiding this comment

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

Two things to note about these lines:

  • It's fine to use relative URLs with pushState, so I think we'll want to do that and thus drop document.location.origin here for conciseness.
  • This will always evaluate to ?${queryString} since by javascript operator precedence, this is equivalent to
(document.location.origin + document.location.pathname + queryString) ? `?${queryString}` : "/"

I believe we want to do something like

const targetUrl = document.location.pathname + (queryString ? `?${queryString}` : "")

where we can drop the / in the ternary operator as it'll come from pathname.

@sachitv
Copy link
Contributor Author

sachitv commented Mar 8, 2021

Thanks for the feedback @vdonato . I’ll make the changes this week and add the unit tests as well.

@stale
Copy link

stale bot commented Mar 22, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 22, 2021
@stale stale bot closed this Mar 23, 2021
@sachitv
Copy link
Contributor Author

sachitv commented Mar 24, 2021

Sorry for the delay, I have been able to make your fixes locally. Though when it comes to creating the unit tests, I might need to specify additional configuration options for these tests namely:

 --server.baseUrlPath="foobar"

I noticed that there's no generic way to pass parameters for individual test cases. Would there be an objection to adding something like this?

I was thinking of creating special folder called 'extra_parameters' alongside scripts and specs in the e2e folder. This would basically contain some .txt files containing text like the above, which is read and passed as command line parameters to the streamlit invocation.

I was wondering if I could use a special toml file here instead? Thoughts @vdonato ?

@sachitv
Copy link
Contributor Author

sachitv commented Mar 24, 2021

Alternatively I could just move my scripts into some sort of 'special' folder and handle the arguments on a case by case basis. Just looking for some guidance on what would be the best path forward.

@vdonato vdonato reopened this Mar 24, 2021
@stale stale bot removed the stale label Mar 24, 2021
@vdonato
Copy link
Collaborator

vdonato commented Mar 24, 2021

Hey @sachitv, no worries about the delay.

As far as testing goes, I think writing tests at the level where we're setting
config options may end up being a bit too much effort for the functionality
we're trying to validate here (it's just a few lines of code, so having to spin
up a streamlit server and pass config options to it + potentially restructure
our scripts so we're able to do so seems like overkill to me).

An approach that will be both easier and more practical given the size of the
function we're testing would be to write tests similar to those that can be
found in the App.handleNewReport describe block of App.test.tsx. The
general structure of these tests will probably look like

  1. Change window.location.pathname to be a pathname we want to test.
    (Note: we'll want to be sure to save the original value and restore it when
    all of the tests have completed)
  2. Initialize a PageInfo protobuf with the queryString we want to test. This
    is similar to how a NewReport message gets created for the handleNewReport
    tests.
  3. Create an app (the same way as in the handleNewReport tests)
  4. Call the handlePageInfoChanged method with the PageInfo proto created
    above
  5. Verify that window.history.pushState was called with the arguments we expect.
    You may have to read up a bit on how jest.spyOn
    works for this if you're not familiar with it. Conveniently there are already
    some usage examples in App.test.tsx.

I listed out some of the cases we want to test in a previous comment.

@sachitv sachitv force-pushed the fix_url_path_issue branch from 5d1dc1c to c0bdaa7 Compare March 25, 2021 06:04
@sachitv
Copy link
Contributor Author

sachitv commented Mar 25, 2021

Thanks for the feedback @vdonato , please can you have a look at these changes? Given i'm not really a TypeScript programmer, I apologize in advance if this freaks you out.

@sachitv sachitv force-pushed the fix_url_path_issue branch 2 times, most recently from f4bceef to b3375f9 Compare March 25, 2021 06:36
Copy link
Collaborator

@vdonato vdonato left a comment

Choose a reason for hiding this comment

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

Hey @sachitv, this looks good to me! I have a few small stylistic points to bring up in the tests, but they're all minor.

Once those are fixed, I can get a second reviewer to take a look (we generally require two people to look at community contributions), and we'll be able to get these changes merged.

This fixes streamlit#2887.
Also adds unit tests to App.test.tsx.
@sachitv sachitv force-pushed the fix_url_path_issue branch from b3375f9 to 59288c7 Compare March 26, 2021 02:16
@sachitv
Copy link
Contributor Author

sachitv commented Mar 26, 2021

Hi Vincent, Appreciate the feedback. I've addressed all your requested changes. Hopefully in a good state to add a second reviewer now?

Copy link
Collaborator

@vdonato vdonato left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for your work on this @sachitv!

I'll ping people to have a second reviewer take a look on Monday (there's a company hackathon going on right now so I'd imagine everyone is heads down on their projects 🙂)

@sachitv
Copy link
Contributor Author

sachitv commented Mar 26, 2021

Looks good to me, thanks for your work on this @sachitv!

My pleasure.

I'll ping people to have a second reviewer take a look on Monday (there's a company hackathon going on right now so I'd imagine everyone is heads down on their projects 🙂)

Nice, have fun!

Btw how does the release process work? Would it be possible to get a minor version release after this merged or would we have to wait for the next scheduled release? It would be really nice to have these fixes available for my work project.

@vdonato
Copy link
Collaborator

vdonato commented Mar 26, 2021

Btw how does the release process work? Would it be possible to get a minor version release after this merged or would we have to wait for the next scheduled release? It would be really nice to have these fixes available for my work project.

We do occasionally do patch releases for issues that sneak in that are especially bad, but I think for an issue of this severity being fixed, it'll be included in the next scheduled release on April 8 (there don't seem to be too many people running into #2887).

Note that if you really need it earlier and are okay with dealing with the potential for a bit of instability, we auto-publish a streamlit-nightly package that'll include this change the next time it's built after this PR is merged.

@sachitv
Copy link
Contributor Author

sachitv commented Mar 28, 2021

Thanks for the response. I think I can wait until April 8 for the next scheduled release.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@sachitv
Copy link
Contributor Author

sachitv commented Mar 29, 2021

Thanks @bh-streamlit and @vdonato for the review. Unfortunately I don't have the bits to merge this. Please could you hit the green button for me?

FYI this is what I see:
image

@vdonato vdonato merged commit f299858 into streamlit:develop Mar 29, 2021
@vdonato
Copy link
Collaborator

vdonato commented Mar 29, 2021

@sachitv merged! Thanks again for your work!

@sachitv sachitv deleted the fix_url_path_issue branch March 29, 2021 23:00
tconkling added a commit that referenced this pull request Mar 30, 2021
* develop:
  Set baseUrl to .
  Speed up CircleCI more (#3025)
  Add events to keep track of theme changes and other theme stats (#3012)
  Have MetricsManager enqueue events when disconnected (#3011)
  Fix for query param issue with base url (#2894)
  Add fuzzy search to selectbox (#2933)
  Informative repr methods for our python classes (#3027)
  ComponentInstance: handle iframe changes (#3015)
tconkling added a commit to tconkling/streamlit that referenced this pull request Mar 30, 2021
* st_form:
  Set baseUrl to .
  Speed up CircleCI more (streamlit#3025)
  Add events to keep track of theme changes and other theme stats (streamlit#3012)
  Have MetricsManager enqueue events when disconnected (streamlit#3011)
  Fix for query param issue with base url (streamlit#2894)
  Add fuzzy search to selectbox (streamlit#2933)
  Informative repr methods for our python classes (streamlit#3027)
  ComponentInstance: handle iframe changes (streamlit#3015)
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.

Set empty query params should only reset the params portion, not the entire URL

2 participants