Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pinning not persistent through soft refreshes #2045

Closed
npfoss opened this issue May 12, 2019 · 1 comment
Closed

Pinning not persistent through soft refreshes #2045

npfoss opened this issue May 12, 2019 · 1 comment

Comments

@npfoss
Copy link
Contributor

npfoss commented May 12, 2019

  • Version: 0.35.0
  • Platform: Ubuntu 16.04, Chrome 74.0.3729.131

Type: Bug/Question

Severity: Medium?

Description:

I'd like to pin things in the browser's localStorage for faster retrieval the next time a user visits my site, but can't seem to get pinned items to persist even soft reloads.

Steps to reproduce the error:

Open the following html file in your browser and check out the console.
It should have an empty pin list, then cat and pin a file, and then have a nonempty pin list.
Turn off WiFi, close the inspector, and do a soft refresh of the page.

  • Expected behavior: still able to cat the file.
  • Actual behavior: Pin list shows up as Array(0) instead of default after hard refresh ([]), can't cat the file.

I don't think it's persisting even without disconnecting from WiFi but that's harder to show.
Am I doing something wrong or is this a bug?

<!doctype html>
<html>
  <head>
    <script src="https://unpkg.com/ipfs/dist/index.js"></script>
  </head>
  <body>
    <script type="text/javascript">
      var IPFS = new window.Ipfs({
        repo: String(Math.random() + Date.now()),
      })

      IPFS.on('ready', () => {

        IPFS.pin.ls().then((pins) => {
          console.log('pins on page load')
          console.log(pins)

          IPFS.cat('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, data) => {
            if (err) { return console.error('ipfs cat error', err) }

            console.log('cat success! file says: ' + data.toString('utf8'))

            IPFS.pin.ls().then((pins) => {
              console.log('pins after cat (should be unchanged)')
              console.log(pins)

              IPFS.pin.add('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP').then((resp) => {
                console.log('"pin.add" response')
                console.log(resp)
                IPFS.pin.ls().then((pins) => {
                  console.log('pins after add')
                  console.log(pins)
                })
              })
            })
          })
        })
      })
    </script>
  </body>
</html>
@alanshaw
Copy link
Member

alanshaw commented May 13, 2019

You're using a different repo each time: repo: String(Math.random() + Date.now())

Try setting that to a static string instead and it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants