Comments (5)
VAX-1857 Why Electric can't load data when phone is offline?
from electric.
from electric.
Hi @thunderfalco,
Below i pasted the relevant snippet from the example app:
const ElectricProviderComponent = ({
children,
}: {
children: React.ReactNode
}) => {
const [electric, setElectric] = useState<Electric>()
useEffect(() => {
let isMounted = true
const init = async () => {
const config = {
debug: DEBUG_MODE,
url: ELECTRIC_URL,
}
const conn = SQLite.openDatabaseSync('electric.db')
const client = await electrify(conn, schema, config)
await client.connect(authToken())
if (!isMounted) {
return
}
setElectric(client)
}
init()
return () => {
isMounted = false
}
}, [])
if (electric === undefined) {
return null
}
return <ElectricProvider db={electric}>{children}</ElectricProvider>
}
The call to useEffect
passes an empty array of dependencies, hence, the callback is executed when the component initially renders. Inside that useEffect
callback we call the asynchronous init
function which electrifies a local SQLite database:
const conn = SQLite.openDatabaseSync('electric.db')
const client = await electrify(conn, schema, config)
await client.connect(authToken())
The last line from the snippet above awaits the call to client.connect
, i.e. it waits until we are connected with the Electric sync server. Since you're offline, this call blocks until you come online. Hence, while offline the code does not reach the setElectric(client)
call and thus electric
is always undefined
. To solve this you could decide to only call client.connect
once you detect that you're online or you could decide not to await the call. Ofcourse, when you're not connected to the sync server, writes won't propagate to and from other clients.
from electric.
I'm closing this issue as I believe my previous comment explains the behavior you're experiencing and this is not a bug. Feel free to re-open with a comment in case there is any problem.
from electric.
Thank you
from electric.
Related Issues (20)
- Generated client Postgres migrations incorrectly split HOT 1
- Upgrade electricsql from 0.10.1 to 0.11.1, can't connect to electric proxy service HOT 2
- Non-atomic transactions with intermediate reads are common HOT 3
- npm ERR! Cannot read properties of null (reading 'matches') HOT 3
- Improve client generation failure messages at the client level HOT 1
- Delayed/Failure to read your writes, lost writes are common HOT 4
- when select where item contains in json array, array_constiains key not recognize, how to filter if json type constains element HOT 2
- [BUG] Syntax error CREATE_REPLICATION_SLOT when install electric-sql with docker HOT 8
- MODULE ERROR: Electric.Replication.PostgresConnector HOT 2
- Possible issue in the new ShapeManager code. HOT 3
- SQLite/PGLite not fully compatible with NextJS HOT 4
- Inactive replication slot causing warnings on DO managed Postgres HOT 6
- Demo example with PostGis plugin?? HOT 1
- Error: FOREIGN KEY constraint failed HOT 4
- [rpc] recv: #SatInStartReplicationResp{`Error: Cannot catch up to the server's current state`} HOT 1
- Unable to install electric-sql on MacOS & Node@22 HOT 2
- Zod rejects UUIDs that Postgres deems valid HOT 1
- `(FunctionClauseError) no function clause matching in Electric.Postgres.Extension.SchemaCache.name/1` HOT 1
- too many arguments on function json_object HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from electric.