question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[clover] Proposal: transferrable assets

See original GitHub issue

Proposal

What is the summary of the proposal?

This proposal adds a capability for static rendering with external content files.

Usecases

  • Blog site
  • Documentation
    • App Shell + Markdown contents (like AIO)
  • Load initial data from JSON and fetch fresh one.

What is the proposal?

Builder-side

Adding a transferAssets option to the @nguniversal/builders:static-generator, which is an array that accepts paths of assets. It is relative from the output path of the browser target.

       "build-static": {
          "builder": "@nguniversal/builders:static-generator",
          "options": {
            "browserTarget": "clover:build:production",
            "routes": [
              "/",
              "pokemon/pikachu",
              "pokemon/charmander",
              "pokemon/squirtle",
              "pokemon/bulbasaur"
            ],
            "transferAssets": [
              "pokemon.json"
            ]
          }
        }

Engine-side

Embedding assets as a JSON state immediately after ngRenderMode has been built. TransferState will be initialized with the state.

      // Embed assets within transfer state
      if (options.transferAssetsPaths) {
        const assets = await Promise.all(
          options.transferAssetsPaths.map((assetPath) => ({
            assetPath,
            content: fs.promises.readFile(path.resolve(options.publicPath, assetPath), 'utf-8'),
          })),
        );
        const assetMap = assets.reduce(
          (map, asset) => ({ ...map, [asset.assetPath]: asset.content }),
          {},
        );
        const state = JSON.stringify(assetMap);
        this.embedTransferState(doc, ngRenderMode.appId, state);
      }

      await ngRenderMode.getWhenStable();

This is an implementation for proof of concept. I don’t think it is production-ready but enough to explain what this proposal aims for.

https://github.com/lacolaco/universal/commit/52f7b7de5099bf0bc9fccbc8a914e92374572ca2

Is there anything else we should know?

Considerations

  • jsdom doesn’t support intercepting to XHR, so CustomResourceLoader cannot help this usecase.
  • At first, I thought assets from the browser target can be used for this purpose, but assets can contain non-text files like images. So explicit option would be needed.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alan-agius4commented, May 26, 2021

I now see what you mean.

Ideally, we should do this without extending the API, we already intercept the all HTTP request in TransferHttpCacheModule.

I think in this case what we can do is add a fallback handler that adds a file:// to requests. XHR can work with local file as well as remote files. That being said, this would need to be tested thoroughly since it can expose a security risk.

JFYI: in the code provided above, the assets are actually stored in that state but are never used by the client, this is because the cache key that the HTTP interceptor uses is more complex https://github.com/angular/universal/blob/094756f95cf8797b28b21e4998a2879ff8973a58/modules/common/clover/src/transfer-http-cache/transfer-http-cache.interceptor.ts#L65

0reactions
angular-automatic-lock-bot[bot]commented, Jul 2, 2021

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing Clover Sales with Commerce Sync - YouTube
Simplify your small business accounting. Commerce Sync eliminates manual data entry and ensures your books are always accurate and complete, ...
Read more >
Meet Clover, The Next Generation Of DeFi On PolkaDot And ...
Clover is a smart contract platform that enables Ethereum developers and projects to migrate their contracts. Clover is a smart contract ...
Read more >
Earn up to 12% extra on Clover crowdloan bonus by using ...
Clover enables users to securely send, receive, and transact tokens and NFT assets on multiple chains all in one wallet.
Read more >
S-1 - SEC.gov
require us to transfer assets upon exercise. The warrants were initially recorded at fair value on the date of grant, and they are...
Read more >
EMERALD Follow-on: "CLOVER" Multiple-Award IDIQ ...
The National Geospatial-Intelligence Agency (NGA) releases its Final Request for Proposals (RFP) for the CLOVER effort, as Solicitation HM0476-21-R-0023, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found