Skip to content

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

Merged
slax57 merged 20 commits intomasterfrom
offline-example
Feb 24, 2026
Merged

Fix <Edit>, <ReferenceField> and <List> to better support offline mode#11161
slax57 merged 20 commits intomasterfrom
offline-example

Conversation

@fzaninotto
Copy link
Copy Markdown
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
Comment thread packages/ra-ui-materialui/src/field/ReferenceField.tsx
@@ -0,0 +1,26 @@
# ra-offline

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

deserves a one line explanation of the demo puropse and usage

Comment thread examples/ra-offline/package.json Outdated
"@tanstack/query-async-storage-persister": "^5.90.22",
"@tanstack/react-query": "^5.90.21",
"@tanstack/react-query-persist-client": "^5.90.22",
"ra-core": "^5.14.1",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

not necessary (ra-ui-mui neither)

Comment thread examples/ra-offline/src/Layout.tsx Outdated
export const Layout = ({ children }: { children: ReactNode }) => (
<RALayout>
{children}
<CheckForApplicationUpdate />
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

unnecessary. But we'd benefit from the react query dev tools

Comment thread examples/ra-offline/src/PostList.tsx Outdated
@@ -0,0 +1,14 @@
import { DataTable, List, ReferenceField } from "react-admin";
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

no difference with a ListGuesser, we should remove it

<title>My Awesome App</title>
<meta name="description" content="My Awesome App description" />
<link rel="icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/apple-touch-icon-180x180.png" sizes="180x180" />
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we can simplify by removing the favicons and loading css

Comment thread examples/ra-offline/package.json Outdated
"react": "^19.0.0",
"react-admin": "^5.14.1",
"react-dom": "^19.0.0",
"react-router": "^7.1.3",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

same, not sure it's required

Comment thread examples/ra-offline/package.json Outdated
"eslint-plugin-react": "^7.37.4",
"eslint-plugin-react-hooks": "^5.2.0",
"globals": "^16.0.0",
"https-localhost": "^4.7.1",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

how is this used?

Comment thread yarn.lock
languageName: node
linkType: hard

"@rollup/pluginutils@npm:^3.1.0":
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

some duplicates here, can we avoid them?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not they are not duplicates, the major version is different (5 vs 3).

We can't avoid the two versions as one is needed by astro and the other one by the vite pwa plugin.

I already ran yarn dedupe btw so they should not remain any duplicates.

Comment thread examples/ra-offline/package.json Outdated
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"serve": "REINSTALL=true PORT=4433 serve dist",
Copy link
Copy Markdown
Collaborator

@WiXSL WiXSL Feb 19, 2026

Choose a reason for hiding this comment

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

make serve-offline fails
serve Should be install in devDependencies

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually I kept this command since it was added by @djhi and figured it was probably useful to force reinstalling the PWA on a real mobile device or something similar. But in the end, I did not use this command, force-reinstalling the PWA is easy enough to do with the desktop browser devtools (and on mobile device you can always remove and reinstall the app), so since it doesn't work I guess I'll simply remove it.

Copy link
Copy Markdown
Collaborator

@WiXSL WiXSL left a comment

Choose a reason for hiding this comment

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

Other than the requested changes, I tested both in development and production (make build-offline + make preview-offline): offline behavior works as expected, including cached navigation/edit flows and mutation replay when reconnecting. Looks good to me.

Good Job 💪

Comment thread examples/ra-offline/index.html Outdated
@slax57 slax57 added this to the 5.14.3 milestone Feb 24, 2026
@slax57 slax57 merged commit 7c23e27 into master Feb 24, 2026
15 checks passed
@slax57 slax57 deleted the offline-example branch February 24, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants