preact-cli icon indicating copy to clipboard operation
preact-cli copied to clipboard

Firebase preload headers + push manifest are incorrect for custom or parameterized routes

Open tomtaylor opened this issue 7 years ago • 7 comments

Do you want to request a feature or report a bug?

Bug.

What is the current behaviour?

The generated firebase.json config uses incorrect route paths for custom or parameterized routes, when generating the HTTP link preload headers. It assumes the route's path is the same as the filename of the route, which it often isn't.

In my situation, I have a group route, which is inside preact-router's Router as <GroupPage path="/groups/:groupId" />, but the firebase.json file contains:

      {
        "source": "/group",
        "headers": [
          {
            "key": "Link",
            "value": "</bundle.86b8e.js>; rel=preload; as=script, </style.785b8.css>; rel=preload; as=style, </route-group.chunk.c23fb.js>; rel=preload; as=script"
          }
        ]
      }

If the current behaviour is a bug, please provide the steps to reproduce.

Generate a firebase.json for a route that's implemented using a path and filename that differ.

What is the expected behaviour?

Ideally, preact-cli would inspect the paths being used in the Router component and generate from those. But that seems quite difficult and might enforce a dependency on supported routers. A simpler approach might be to read a preload mappings file that's kept in sync with the Router mappings, or to inspect a special comment in each route file, that's also kept in sync.

I think a custom preload mappings file would be my preferred approach, as it would allow for explicit custom mappings. For example, my app requires authentication, so I'd like to always preload the login route from the home page, because 90% of visits will require it. I'm imagining something like a preload-mappings.json containing:

{
  "/": ["login", "home"],
  "/groups/*": ["group"],
  "/groups/*/topics/*": ["topic", "group"]
}

I'd be happy to have a go at a PR for this, but I'd like to sanity check this approach before I do the work! The same issue applies with the the preact-cli-plugin-netlify plugin.

tomtaylor avatar Sep 22 '18 17:09 tomtaylor

I didn't know that's a thing. I'll raise a PR to fix this

prateekbh avatar Sep 22 '18 18:09 prateekbh

Btw what version are u using?

prateekbh avatar Sep 22 '18 18:09 prateekbh

@lukeed @developit can u point me to the place where is this generated?

prateekbh avatar Sep 22 '18 18:09 prateekbh

@prateekbh I’m using 2.2.1.

tomtaylor avatar Sep 22 '18 20:09 tomtaylor

I should also say that the push-manifest.json exhibits the same problem.

tomtaylor avatar Sep 22 '18 20:09 tomtaylor

yep this problem still remain I guess

prateekbh avatar Sep 22 '18 20:09 prateekbh

Well this is a bit complicated, I dont know a good way of mentioning this in push-manifest or firebase.json

prateekbh avatar Sep 22 '18 20:09 prateekbh