near / react-on-chain

Improved execution layer for NEAR decentralized frontend components
https://roc-docs.near.dev/
23 stars 5 forks source link

Add block height versioning #377

Closed pavelisnear closed 1 month ago

pavelisnear commented 2 months ago

This PR introduces a way to set specific block height for a component. If no block height specified - the latest version is being fetched.

Example

A component using two instances of the same component, but the first one is with a specific block height.

import SandboxWithBlockHeight from 'near://pavel-pagoda.near/PavelSandbox@114965395';
import SandboxLatest from 'near://pavel-pagoda.near/PavelSandbox';

export default function () {
  return (
    <div>
      <h1>Sandbox with a block height:</h1>
      <SandboxWithBlockHeight />
      <hr />
      <h1>Sandbox latest:</h1>
      <SandboxLatest />
    </div>
  );
}

Should produce two instances of the same component, but with the respected versions:

image

Fixes https://github.com/near/bos-web-engine/issues/95

vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
bos-web-engine ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 10:14pm
bos-web-engine-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 10:14pm
bos-web-engine-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 10:14pm
mpeterdev commented 1 month ago

I have been testing this and it seems to be working well when versions are recent enough to be serviced by a non-archival RPC node. I am working on getting us answers on how to proceed with fetching older component versions

pavelisnear commented 1 month ago

New flag added to the Inspector

State 1: enableBlockHeightVersioning is set to true

image

State 2: enableBlockHeightVersioning is set to false (default) - the block height is ignored and the latest version fetched

image

Component code:

import BlockHeightWithFlagTest from 'near://pavel-pagoda.near/BlockHeightWithFlagTest@115160709';
import BlockHeightWithFlagTestLatest from 'near://pavel-pagoda.near/BlockHeightWithFlagTest';

export default function () {
  return (
    <div>
      <h1>Sandbox with a block height:</h1>
      <BlockHeightWithFlagTest />
      <hr />
      <h1>Sandbox latest:</h1>
      <BlockHeightWithFlagTestLatest />
    </div>
  );
}