Skip to content

Fix offline query parameter handling in embed route#100

Open
Copilot wants to merge 5 commits intomainfrom
copilot/fix-embed-route-parameters-offline
Open

Fix offline query parameter handling in embed route#100
Copilot wants to merge 5 commits intomainfrom
copilot/fix-embed-route-parameters-offline

Conversation

Copy link

Copilot AI commented Jan 27, 2026

Query parameters to the embed route (?trainType=c51&messages=["hello"]) fail in offline mode if the exact URL wasn't previously cached. Service worker performs literal cache key matching including query strings.

Changes

  • Strip query parameters for navigation request caching: Cache keys normalized by removing query strings since HTML content is identical. JavaScript reads parameters from window.location.search at runtime.

  • Extract createRequestWithoutQuery helper: Eliminates duplication between online caching and offline matching logic. Short-circuits when no query parameters exist.

const createRequestWithoutQuery = (request: Request): Request => {
  const url = new URL(request.url);
  if (!url.search) return request;
  url.search = '';
  return new Request(url.toString(), { /* preserve request properties */ });
};

// Online: cache without query params
cache.put(createRequestWithoutQuery(request), response);

// Offline: match without query params
caches.match(createRequestWithoutQuery(request));

Result: Visiting embed.html online enables embed.html?trainType=c51&messages=["test"] offline.

Original prompt

In offline mode, query parameters to the embed route do not work correctly if they weren't used online. We should be able to set the train type or messages while offline since there is no new assets being loaded/required.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 27, 2026 02:20
Co-authored-by: scaryrawr <661373+scaryrawr@users.noreply.github.com>
Co-authored-by: scaryrawr <661373+scaryrawr@users.noreply.github.com>
Co-authored-by: scaryrawr <661373+scaryrawr@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix embed route query parameters for offline mode Fix offline query parameter handling in embed route Jan 27, 2026
Copilot AI requested a review from scaryrawr January 27, 2026 02:24
@scaryrawr scaryrawr marked this pull request as ready for review January 27, 2026 14:53
Copilot AI review requested due to automatic review settings January 27, 2026 14:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes offline query parameter handling in the embed route by normalizing cache keys to exclude query parameters. Previously, visiting embed.html?trainType=c51 would fail offline if only embed.html was cached, despite the HTML content being identical.

Changes:

  • Added createRequestWithoutQuery helper function to strip query parameters from Request objects
  • Modified navigation request caching to store responses without query parameters
  • Updated offline cache matching to search without query parameters

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

3 participants