-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Interoperability and wasmJs bugfixes #412
base: main
Are you sure you want to change the base?
Changes from all commits
9f17204
143db14
508fb4a
f13119e
016604d
9e3a4c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ public fun BrowserRouter( | |
initPath: String, | ||
routeBuilder: @Composable RouteBuilder.() -> Unit | ||
) { | ||
BrowserRouter().route(initPath, routeBuilder) | ||
Router.internalGlobalRouter = BrowserRouter().apply { route(initPath, routeBuilder) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the use-case/code for setting this variable? Can't the function just return the Router instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could. I've implemented it this way just to simplify the client code and to be consistent with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can't be called from any non-composable functions like effects, event handlers, view model methods or some global utility functions. |
||
} | ||
|
||
internal class BrowserRouter : Router { | ||
|
@@ -47,11 +47,15 @@ internal class BrowserRouter : Router { | |
|
||
private fun Location.newPath() = "$pathname$search" | ||
|
||
override fun navigate(to: String, hide: Boolean) { | ||
override fun navigate(to: String, hide: Boolean, replace: Boolean) { | ||
if (hide) { | ||
currentLocation.value = to | ||
} else { | ||
window.history.pushState(null, "", to) | ||
if (replace) { | ||
window.history.replaceState("", to) | ||
} else { | ||
window.history.pushState("", to) | ||
} | ||
/* | ||
The history API unfortunately provides no callback to listen to | ||
[window.history.pushState], so we need to notify subscribers when pushing a new path. | ||
|
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.
Why can't we put all parameters to remember? Remember uses its own cache.
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.
Remember only works with a recomposition. The routing changes the composition (
route
calls are leaving and entering the composition when navigating) and remember doesn't work here.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.
Do you have any samples causing the memory leaks (or a reproducer)? I do understand the cause, we create a new RouteBuilder during each composition, but ideally the GC/Compose should be able to remove the object.