Skip to content

Fix <Edit>, <ReferenceField> and <List> to better support offline mode#11161

Open
fzaninotto wants to merge 13 commits intomasterfrom
offline-example
Open

Fix <Edit>, <ReferenceField> and <List> to better support offline mode#11161
fzaninotto wants to merge 13 commits intomasterfrom
offline-example

Conversation

@fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Feb 12, 2026

Problem

Offline apps behave in a strange way, sometimes showing error pages even though they should not.

The offline mode of TanStack Query works fine in a standalone example, so the problems come from react-admin.

We lack a way to properly test offline mode, particularly in the context of a PWA.

Additional specific issues found:

  • <Edit> ignores the redirectOnError prop, making it hard to disable the redirection to the list in case of error (even if there's data in the cache)
  • <ReferenceField> renders an error message even if the reference record is available in the cache
  • <ListView> hides the pagination as soon as a fetch error occurs, preventing the user to go back to a page for which cached data are present

Solution

Build a demo (with Vite PWA plugin), track down the issues and fix them.

When offline, all calls to useQuery return an error... but they also return data.

In a nutshell, we must not only check for errors before deciding to show/return things but also that no data is available for offline support to work correctly

  • Fix ReferenceField
  • Fix ListView
  • Fix Edit
  • Test on a larger app (e.g. Atomic CRM)

If we have a NetworkError and valid data, it means we're offline and that TanStack query returned stale data.

How To Test

  • make build-offline
  • make preview-offline

(the offline mode doesn't work in dev mode, that's a limitation of vite-pwa)

Use the DevTools to simulate Offline mode when needed.

The PWA should be able to fetch data from the cache, even when reloading the whole app while offline (thanks to the service worker and the TanStack query Persister).

Known issue: TanStack query discards the cached data if you reload the app 2 times. See related issue.

The PWA should allow to perform mutations while offline, and replay the mutations when back online.

Note: Since this demo is hooked up to JSONPlaceholder API, the changes are not persisted for real. But the mutation should be visible in the Network tab and not trigger errors.

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The PR includes unit tests (if not possible, describe why) -- debatable
  • The PR includes one or several stories (if not possible, describe why)
  • The documentation is up to date -- debatable

@fzaninotto fzaninotto added the WIP Work In Progress label Feb 12, 2026
@slax57 slax57 changed the title Fix offline Fix <Edit>, <ReferenceField> and <List> to better support offline mode Feb 17, 2026
@slax57 slax57 added RFR Ready For Review WIP Work In Progress and removed WIP Work In Progress RFR Ready For Review labels Feb 17, 2026
const getRecordRepresentation = useGetRecordRepresentation(reference);

if (error) {
if (error && referenceRecord == null) {
Copy link
Collaborator

@WiXSL WiXSL Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the app is online and a cached referenceRecord exists, it can hide real API errors

// Potencial Fix
if (error && (referenceRecord == null || !referenceFieldContext.isPaused)) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Development

Successfully merging this pull request may close these issues.

4 participants