-
Notifications
You must be signed in to change notification settings - Fork 690
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
Prevent duplicate event handler registration by configuring the router only once #519
Prevent duplicate event handler registration by configuring the router only once #519
Conversation
…r only once Remove the `options` parameter from `page.start`/`createPage` (it wasn't used anyway) and also from the `Page` constructor together with the `configure` call there. That ensures that the router is configured only once, with the user-supplied `options`, instead of being configured twice: first with default `options` in constructor, second time with user-supplied `options` in `page.start`. Fixes a real-world issue where passing `{ click: false }` to `page.start` didn't prevent adding the global click handler to the document anyway, because the default value of the `click` option is `true`.
@matthewp When and if you merge this, could you update the |
Yup! |
This seems to be causing an issue for me around page._window not being defined now that .configure() is not being called. Does that make any sense? I have not dug deeply on this yet. |
Just verified that things are working for me as expected in 1.11.0, but are breaking due to _window being undefined in 1.11.1. |
Seems to be required to call page.start() in 1.11.1. Does there need to be a major version bump here? |
Hi @andyburke, do you use the library without ever calling Does that help? I'd like to learn more about how exactly you use page.js, because the |
I would call things like:
before eventually calling page( url ) to start routing. With 1.11.1 I was suddenly hitting page._window not being defined, whereas I had not had that before. Unfortunately, I already switched things around to use page.start() in my code so I could make progress, so I don't have a call stack for you. |
@andyburke Defining route handlers before |
Actually, now I am struggling with this... I'm doing a page.start( { dispatch: false } ), but then calling page.show( url ) and it is not dispatching, I think due to this change: 2447b23#diff-50e3e6872ec225cd4caa566f1f15e89cR603 Why is the 'dispatch' argument to page.show() ignored in preference to page instance's _dispatch?(which I think should indicate initial dispatch, not all dispatching, right?) |
btw ... why am I always the one with dispatching issues?: d5c92c1 |
I agree that's a bug.
It doesn't even need to be an instance property visible to everyone. Local variable inside |
Remove the
options
parameter frompage.create
/createPage
(it wasn't used anyway) and also from thePage
constructor together with theconfigure
call there.That ensures that the router is configured only once, with the user-supplied
options
, instead of being configured twice: first with defaultoptions
in constructor, second time with user-suppliedoptions
inpage.start
.Fixes a real-world issue where passing
{ click: false }
topage.start
didn't prevent adding the global click handler to the document anyway, because the default value of theclick
option istrue
.How I tested this:
Unit tests still pass both in Node and in browser.
I also tested the router in WordPress.com Calypso and it works as expected. The issues described in
are no longer present and everything works as expected again 👌
Based on earlier PR by @kaisermann (#509)
Fixes #508