Skip to content

More banner message fun#13368

Open
LawnGnome wants to merge 4 commits intorust-lang:mainfrom
LawnGnome:fix-banner-html
Open

More banner message fun#13368
LawnGnome wants to merge 4 commits intorust-lang:mainfrom
LawnGnome:fix-banner-html

Conversation

@LawnGnome
Copy link
Copy Markdown
Contributor

Putting this up as a draft because I don't even know how I feel about it right now.

To recap, the problem:

  1. We want to be able to post HTML banner messages with links. (In this case, specifically for the upcoming docs.rs build changes).
  2. app: enable HTML for banner messages #13341 did the initial work there, but it turns out we then ran into links in notifications doesn't redirect to links' target mansona/ember-cli-notifications#269, which meant that links in banner messages were unclickable in practice in the Ember frontend.
  3. Adding an onclick to the banner message works locally, but staging and prod apply a content security policy that disables it. This is good, if inconvenient.

I also realised today that there was another missing feature: we want this to be dismissible and for the user's browser to persist that it has been dismissed, otherwise we're going to spend the next three and a bit weeks annoying our users in general, and popping a notification over the log in link for most users every time they open or reload a crates.io tab in particular.

I've gone through a few options here:

  1. We can just straight up add the hash for the onclick to the content security policy as a one-off. I'm not super keen on this, because it's an implementation detail we're going to forget with how infrequently we use BANNER_MESSAGE, but it's possible.
  2. I played around with monkey-patching the notification service, but that's ugly, tricky, and feels extremely fragile.
  3. We could add the banner straight up to the HTML template. I'm not actually totally opposed to that, but then we have to implement logic to handle dismissing the banner, which ends up looking a lot like ember-cli-notifications anyway.

So, instead, this PR does a few things (this lines up with the commits; a commit-by-commit review might be the best way to review this):

  1. Uses pnpm's patching support to patch ember-cli-notifications to this branch on a fork, which includes the bug fix alluded to above and adds an onDismiss handler that we can use to implement the persistence support mentioned above.
  2. Actually implements the persistence behaviour on Ember.
  3. Adds onDismiss to the Svelte reimplementation of notifications.
  4. Uses that to implement the persistence behaviour on Svelte.

This may be overkill. We may not want the persistence behaviour in general moving forward, in which case the cookie handling could be simplified and we just revert it after May 1st. We may want to migrate banner messages to not use the notification support at all, but to appear as a top-of-page banner instead, in which case we have a different — but maybe simpler — set of problems. We may also just decide that we don't care very much about this docs.rs banner after all, and not do anything. (In that case, let's revert #13341 as well.)

But I want to hear what the rest of you all think.

@LawnGnome LawnGnome requested a review from a team April 8, 2026 01:23
@LawnGnome LawnGnome self-assigned this Apr 8, 2026
@LawnGnome LawnGnome added C-enhancement ✨ Category: Adding new behavior or a change to the way an existing feature works A-frontend 🐹 A-svelte labels Apr 8, 2026
* @returns {void}
*/
#writeDismissedSet(set) {
this.cookies.write(BANNER_MESSAGE_COOKIE_NAME, [...set.values()].join(','));
Copy link
Copy Markdown
Member

@Turbo87 Turbo87 Apr 8, 2026

Choose a reason for hiding this comment

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

View changes since the review

cookies are usually restricted to ~4KB. I guess this most likely won't cause any issues for us, but I'm curious if there was a reason for using cookies over local storage (which I think has a ~5MB limit)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The reason is that I'm old. Local storage probably would be better.

Comment on lines +164 to +173
let dismissFired = false;
let notification = state.info('Message', {
onDismiss: local => {
expect(local).toBe(notification);
dismissFired = true;
},
});

state.removeNotification(notification);
expect(dismissFired).toBe(true);
Copy link
Copy Markdown
Member

@Turbo87 Turbo87 Apr 8, 2026

Choose a reason for hiding this comment

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

View changes since the review

I guess this works well enough, so don't feel the need to refactor this, but if you wanted to then https://vitest.dev/api/mock.html might be an alternative for this pattern :)

Comment on lines +204 to +206
"patchedDependencies": {
"ember-cli-notifications@9.1.0": "patches/ember-cli-notifications@9.1.0.patch"
}
Copy link
Copy Markdown
Member

@Turbo87 Turbo87 Apr 8, 2026

Choose a reason for hiding this comment

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

View changes since the review

I'm not a huge fan... 😅

I was gonna propose opening an upstream PR, but apparently that had already happened about 4 years ago 😞

then I was gonna propose using resolutions to point to a fork, but admittedly the committed patch might ultimately be better since the fork could be deleted, preventing our project from building.

so I guess I'm okay with this as a temporary measure, since we'll hopefully be switching over to the Svelte app soon anyway :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

so I guess I'm okay with this as a temporary measure, since we'll hopefully be switching over to the Svelte app soon anyway :)

Yeah; if I thought this was going to last more than (hopefully) a couple of months, I'd probably do something more robust like actually publish the forked package.

@Turbo87
Copy link
Copy Markdown
Member

Turbo87 commented Apr 8, 2026

one thing I forgot during the first review... could you add tests? 😅

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

Labels

A-frontend 🐹 A-svelte C-enhancement ✨ Category: Adding new behavior or a change to the way an existing feature works

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants