Skip to content

Conversation

@jagthedrummer
Copy link
Contributor

@jagthedrummer jagthedrummer commented Jul 10, 2025

This adds support for Rails Progressive Web App feature which was added in Rails 7.2.

Fixes: #2100

This basically adds the same starter bits that are generated with a new Rails application.

  • A starter file for serving /manifest.json so that an app can be "installed" locally
  • A starter file for serving /service-worker.js
  • A commented out line in app/views/layouts/_head.html.erb for pointing browsers at /manifest.json
  • Two commented out lines in config/routes.rb for serving /manifest.json and /service-worker.js

To make use of these you'll need to uncomment things as appropriate and customize them to your needs.

NOTE: To make use of the Service Worker you need to register it somehow via your own app Javascript. It's up to you to decide if you want to register it automatically or prompt users to opt-in.

After uncommenting the lines for enabling the manifest you should see some way to install the app (in browsers that support installation of PWAs). This is what it looks like in Chrome:

CleanShot 2025-07-11 at 15 29 42

After clicking the button you'll be prompted to install the app:

CleanShot 2025-07-11 at 15 30 23

And then it will be opened in a new instance of the browser that does not have the normal browser chrome but just a header bar for your app:

CleanShot 2025-07-11 at 15 10 12

On MacOS your app will show up in Launchpad:

CleanShot 2025-07-11 at 15 16 18

@jagthedrummer jagthedrummer marked this pull request as ready for review July 11, 2025 20:33
Copy link
Contributor

@zackgilbert zackgilbert left a comment

Choose a reason for hiding this comment

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

Comment inline. I'm okay with this (it's a step closer), but think we can go a step further that actually enables them so a project could be added out of the box.

<%= capybara_lockstep if defined?(Capybara::Lockstep) %>

<%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
<%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why you wouldn't just enable this by default?

"name": "<%= t('application.name') %>",
"icons": [
{
"src": "/heroku-logo.png",
Copy link
Contributor

Choose a reason for hiding this comment

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

We'd want to use our app's logo, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the starter repo this is the app logo. Is there some other file you think we should point at by default?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh. Didn't realize. Was thinking it was the logo in the assets folder or something like that. No worries then, if that's the main logo. I thought it was the heroku logo, which didn't make sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that files has a weird name for some reason...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And we do seem to have several copies of more-or-less the same logo scattered around the starter repo. Might be worth consolidating and cleaning up.

extending = {only: []}

# Render dynamic PWA files from app/views/pwa/* (remember to link manifest in layouts/_head.html.erb)
# get "manifest" => "rails/pwa#manifest", as: :pwa_manifest
Copy link
Contributor

Choose a reason for hiding this comment

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

Feel like these (this and service-worker on the next line) could be enabled as well, no? Any reason not to?

Copy link
Member

@pascallaliberte pascallaliberte left a comment

Choose a reason for hiding this comment

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

@jagthedrummer @zackgilbert

I feel like a bullet_train thing to do would be to have a pwa_enabled? helper method returning true if ENABLE_PWA=true env var is set.

What do you all think?

@jagthedrummer
Copy link
Contributor Author

@zackgilbert As far as whether or not to enable these things by default I have a few kind of related thoughts:

  1. Doing this keeps us up with Rails and if people are already familiar with what Rails does around this then this is kind of "expected".
  2. Enabling them by default could potentially unintentionally introduce a new user-facing feature if someone isn't paying that close of attention to release notes.
  3. People will likely want to tweak the manifest before letting it get into the wild. If someone did unintentionally release this, and then went back to change the manifest, anyone who had already installed it would still see whatever was in the original version of the manifest. Like if they went back to change the theme_color and icon people who had already installed would still see the previous color and logo.

All that said, I did go back and forth over whether we should enable this stuff by default, and the reasons listed above just tilted me towards leaving them disabled. I'm happy to consider reasons for enabling them by default.

@jagthedrummer
Copy link
Contributor Author

@pascallaliberte having some configs was one of my first considerations: #2100 (comment)

Might be the way to go...

@jagthedrummer
Copy link
Contributor Author

If we did go with the config/helper method route we could move the routes and the layout bits into core instead of having them live in the starter repo.

@pascallaliberte
Copy link
Member

@jagthedrummer @zackgilbert

How about manifest.json.example?

And instead of an ENV var, we just check the presence of the manifest.json file?

Solves the file overwriting, allows us to stuff those routes in gems, we could have smart defaults in that file (logo path), and to make it super clear to partial ejectors, the helper could be named manifest_for_pwa_exists?

@jagthedrummer
Copy link
Contributor Author

How about manifest.json.example?

And instead of an ENV var, we just check the presence of the manifest.json file?

🤔 Interesting idea...

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Rails PWA support

4 participants