Skip to content

Service Worker support for Hilla Endpoints #7563

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

Open
10 tasks
platosha opened this issue Apr 29, 2025 · 0 comments
Open
10 tasks

Service Worker support for Hilla Endpoints #7563

platosha opened this issue Apr 29, 2025 · 0 comments
Labels
hilla Issues related to Hilla PRD v24.8

Comments

@platosha
Copy link
Contributor

Description

Support using Hilla endpoints from a service worker context to enable fetching data for offline support and background sync use cases.

Tier

Free

License

Apache 2.0

Motivation

Background

Vaadin current support of Service Workers is provided with the @PWA annotation. Using this annotation enables service worker Vite plugin and generates a template sw.ts that comes pre-configured for chaing the frontend resources of the application, including Hilla views, for offline support.

The service worker code can be optionally customized by developers for expanding its use beyond frontend resource caching, potentially also for storing data offline and syncing it on the background, without requiring the user to open or interact with the application.

Problem

Hilla endpoints do not work in when called from sw.ts or its imports due to limitations in Hilla:

  • Endpoints client does not compile in a service worker due to TypeScript errors for missing browser Window / DOM API. Thus the generated endpoints that involve the client are not importable.
  • HTTP requests do not pass the CSRF protection due to missing the token.

Thus it gets more difficult for developers to make server requests from a service worker compared with using Hilla endpoints from a regular browser tab context.

Solution

Remove the limitations that block using Hilla endpoints from a service worker context and make regular Hilla endpoints work same way as in the regular browser window script context.

Add documentation describing customizing the service worker and using Hilla endpoints in it.

Notes

Epic issue: vaadin/hilla#2814

Requirements

  • Users can import Hilla endpoints from a customized sw.ts without errors.

  • Calls to Hilla endpoints from a sw.ts work.

  • Documentation

    • A Hilla guide describing offline support with customized sw.ts and example of using Hilla endpoints

Nice-to-haves

No response

Risks, limitations and breaking changes

Risks

Limitations

Breaking changes

Out of scope

  • Support for using Flux endpoints in Service Worker context is out-of-scope due to known limitations in the Atmosphere JS library.

Materials

No response

Metrics

No response

Pre-implementation checklist

  • Estimated (estimate entered into Estimate custom field)
  • Product Manager sign-off
  • Engineering Manager sign-off

Pre-release checklist

  • Documented (link to documentation provided in sub-issue or comment)
  • UX/DX tests conducted and blockers addressed
  • Approved for release by Product Manager

Security review

None

@platosha platosha added this to Roadmap Apr 29, 2025
@platosha platosha moved this to June 2025 (24.8) in Roadmap Apr 29, 2025
@platosha platosha added the hilla Issues related to Hilla label Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hilla Issues related to Hilla PRD v24.8
Projects
Status: June 2025 (24.8)
Development

No branches or pull requests

1 participant