podium-lib / client

Client for fetching Podium component fragments over HTTP.
MIT License
7 stars 6 forks source link

Implement usage of manifest scope field #331

Closed digitalsadhu closed 11 months ago

digitalsadhu commented 11 months ago

This PR implements asset filtering in the Podium client based on the new asset scope field as added in this PR https://github.com/podium-lib/utils/pull/212

TODO:

The details

trygve-lie commented 11 months ago

What is the purpose of isFallback? What's its use case?

digitalsadhu commented 11 months ago

What is the purpose of isFallback? What's its use case?

There's was no easy way to know when the client "fell back" once outside the content resolver as it transparently replaces the content with the fallback content. I thought initially that the success property would do that but success is always true regardless of whether the content ends up being content or fallback.

So once outside the content resolver, in resource.js isFallback gives us a way to work out how to do the filtering of the assets, either content or fallback.

const { manifest, headers, redirect, isFallback } = await this[_resolver].resolve(outgoing);

return new Response({
    ...
    css: utils.filterAssets(isFallback ? "fallback" : "content", manifest.css),
    js: utils.filterAssets(isFallback ? "fallback" : "content", manifest.js),
    ...
});

The only other options I tried (and don't really like) is to modify the actual manifest object on the outgoing object while still inside the content resolver (before returning the outgoing object to the resolver)

outgoing.manifest.js = utils.filterAssets("content", outgoing.manifest.js);
outgoing.manifest.css = utils.filterAssets("content", outgoing.manifest.css);

This modifies the js and css arrays in place but broke a bunch of tests because in some case the beforeStream events were suddenly wrong, I think because they are events and were happening out of order.

github-actions[bot] commented 11 months ago

:tada: This PR is included in version 4.6.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] commented 11 months ago

:tada: This PR is included in version 5.0.0-next.14 :tada:

The release is available on:

Your semantic-release bot :package::rocket: