Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Produce valid URLs for client assets pertaining to routes with dynamic params #747

@alexdilley

Description

@alexdilley

Network requests for assets such as /client/[slug].c6e3f42d.js should be URI-encoded since square brackets are reserved characters under RFC 3986. AWS API Gateway, for example, does not allow requests for such URLs, hence where an AWS stack is used to proxy requests Sapper is thus not supported.

Propose that encodeURIComponent() wraps the href of client assets.

(I've been able to locate what I believe would be the relevant points in code to correct URLs to stylesheets, but JS assets appear to be a lot trickier to track down.)

--- a/runtime/src/app/app.ts
+++ b/runtime/src/app/app.ts
@@ -359,7 +359,7 @@ export async function hydrate_target(target: Target): Promise<{
 }

 function load_css(chunk: string) {
-       const href = `client/${chunk}`;
+       const href = `client/${encodeURIComponent(chunk)}`;
        if (document.querySelector(`link[href="${href}"]`)) return;

        return new Promise((fulfil, reject) => {
diff --git a/runtime/src/server/middleware/get_page_handler.ts b/runtime/src/server/middleware/get_page_handler.ts
index c7c88e4..7708296 100644
--- a/runtime/src/server/middleware/get_page_handler.ts
+++ b/runtime/src/server/middleware/get_page_handler.ts
@@ -308,7 +308,7 @@ export function get_page_handler(
                                });

                                styles = Array.from(css_chunks)
-                                       .map(href => `<link rel="stylesheet" href="client/${href}">`)
+                                       .map(href => `<link rel="stylesheet" href="client/${encodeURIComponent(href)}">`)
                                        .join('')
                        } else {
                                styles = (css && css.code ? `<style>${css.code}</style>` : '');

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions