-
Notifications
You must be signed in to change notification settings - Fork 238
fix: prevent double initialization #284
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
Deploy Success! Built with commit 280d898 |
src/netlify-identity.js
Outdated
@@ -141,9 +145,14 @@ observe(store, "siteURL", () => { | |||
if (store.siteURL === null || store.siteURL === undefined) { | |||
localStorage.removeItem("netlifySiteURL"); | |||
} else { | |||
const currentURL = localStorage.getItem("netlifySiteURL"); |
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'm a bit confused by this.
Looking at the code I initially thought we could use the change
argument passed to the handler instead of relying on localStorage
, but then realised that it doesn't makes sense for mobx
to report identical values.
Did a quick test and:
const store = observable({
siteURL: null,
});
observe(store, "siteURL", (change) => {
console.log(JSON.stringify(change));
});
store.siteURL = "hello";
store.siteURL = "hello";
Only prints a log message on the first assignment to siteURL
, so I'm not sure how we're getting identical values here. The only thing I can think of is that localStorage
and store. siteURL
become out of sync for some reason.
Also, this changes the current behaviour of calling store.init
when siteURL
is set to null
or undefined
, but I haven't been able to figure if there are any implications to that.
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.
@erezrokah as far as I can tell this is only affected by localhost, so I don't think it poses any issues. it's hard to say for sure because I only sort of get how mobx
works, so I was just testing workflows
maybe we can publish a beta and put it on a few sites to test before doing a full release?
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.
LGTM
I released a beta to use it, load the JS from https://unpkg.com/netlify-identity-widget@1.8.1-beta.0/build/netlify-identity-widget.js instead of the standard include URL @erezrokah do you have projects you want to test this against? it works as expected with the repo examples, but those are pretty bare bones |
Beta is a good idea, but we had the same issue with the CMS beta versions of trying to figure out how to test the beta channel (eventually we stopped using the beta channel). I finally had some time to look into the original issue with the repo https://github.com/learnwithjason/stripe-jamstack-subscriptions and I think I was able to trace the underlying issue and wrote a test to reproduce it: The
On initial load we attempt to create a new instance here:
So far so good. The thing is that
which will end up calling
In both cases
Which is set to the store here:
Which triggers the The solution was to return |
@erezrokah thanks so much for doing this research! I’m not sure where to go from here, though — do you want me to close this PR and you'll open a different one? or should we make the patch here instead? |
Refactor callback management to use `Map` so that we can unregister handlers without changing the current behavior. Co-authored-by: Cassidy Williams <cassidy@netlify.com>
GoTrue was instantiated twice when on localhost and netlifySiteURL configured
94462e4
to
280d898
Compare
I should have been more clear about that. I cherry picked the commit from that branch into this PR, did another rebase and pushed the changes. I'm good with merging if your are. |
(NOTE: don’t merge this until #283 goes in)
when setting the URL, the initialize function needs to be called or else the widget gets stuck. however, when no change is required, the init function was being called twice anyways, which caused some undesirable behavior
this adds a check to fix that