-
Notifications
You must be signed in to change notification settings - Fork 98
Fix multiple updates in a single render in tests #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This reverts commit dc46057.
QueryParamProvider, | ||
QueryParamContext, | ||
QueryParamContextValue, | ||
} from './QueryParamProvider'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes I made modify the parameters of updateUrlQuery
and the signature of QueryParamContext
and the type QueryParamContextValue
, which are library exports. However, these aren't documented in the README or included in any examples. Would taking these out of the library exports be considered a breaking change? They seem like internal details of the library to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's fine
import { QueryParamProvider } from '../QueryParamProvider'; | ||
import { makeMockLocation, makeMockHistory } from './helpers'; | ||
|
||
// ¯\_(ツ)_/¯ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should I do with these tests? I wanted to make sure the history-generating code in QueryParamProvider was still working, but I'm no longer passing history down via context.
Ooo cool, I wanted to get around to reworking how location/history were provided after I realized location needs to be requested at the last minute. I've made a ton of changes to the lib today (spent the day on it) that will make merging this ... difficult. But it seems like it would be worthwhile at first glance. I'll need to read through it more carefully later |
if you have some bandwidth to fix the merge conflicts, that'd be great too! Let me know if so, otherwise I'll probably look at it tonight or this weekend |
Ok going to take a look, thanks |
Continuing in #86 |
Resolves #62 . This is a follow-on from issue #54 and PR #61 , but the fix doesn't require
history
to havehistory.location
defined, so now works with tests outside a browser.The approach I took was to move the refs up. Rather than each useQueryParam/s hook maintaining its own ref of the last version of the location it received, the top level provider should maintain a single location ref instead, and updates to the location should work with this shared ref. (The previous approach in #61 was like a shared ref approach, too: when it exists,
refHistory.current.location
is up-to-date everywhere in the app because there's only one history, butrefLocation.current
isn't guaranteed to be up-to-date if two different hooks call setQuery without re-rendering between calls.) I introduced a new internal-onlyLocationProvider
component to manage this ref and provide down a single cached updater callback.