-
Notifications
You must be signed in to change notification settings - Fork 120
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
fix(examples): Fix React projects not providing correct client to app #1191
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
baf46ae
Fix web-wa-sqlite wrong client issue
msfstef 847dce5
Fix tauri strict mode issue
msfstef 22c301b
Fix react native client cleanup
msfstef c7aecb6
Fix expo client cleanup
msfstef 4d42640
Fix client cleanup on checkout example
msfstef d594ca3
Fix client cleanup on introduction initialization
msfstef 2619791
Fix client cleanup on recipes
msfstef 436e211
Update react integration docs
msfstef 95d6bc4
Add changeset for template generation
msfstef File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-electric-app": patch | ||
--- | ||
|
||
Update templates to fix incorrect client providers in React projects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 component could have re-rendered during any of the following three
await
s.The returned cleanup function should set an
ignore
var that is checked after each await, returning immediately if true. This would prevent any unnecessary work and setting the electric state var to the wrong instance.This is sort of what the
isMounted
did.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 issue is that electrification affects global components like the registry - the
isMounted
that we had before (or any check of this kind that we add) will still likely cause a mixup.Basically the first database connection opened is fed to
electrify
and starts a satellite process - even if the electrified instance is not set at that point withsetElectric
, subsequent calls will create new database connections that will be fed to the client but not the satellite as the satellite is global and will use the first one (and first notifier), see:electric/clients/typescript/src/satellite/registry.ts
Lines 79 to 91 in e92a7e3
This leads to a weird state where the client performs the writes and reads correctly but the satellite is still using the first notifier and adapter/connection.
I find it better to let it do the little additional work (which is only really done in React's StrictMode) and ensure that we end up with the correct setup.
An alternative route, which I think might also be a good solution, is to have a separate, outside of the component top-level
initElectric
which keeps track of whether it has been initialized or not, and the component doesn't need to worry about multiple calls and cleanups as much.