github:即使重新加载浏览器也会留下评论,为什么? [英] github: comment will be remaining even if reload browser, why?

查看:16
本文介绍了github:即使重新加载浏览器也会留下评论,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用 github 的 issue page 写评论时,我注意到即使我重新加载浏览器,评论体仍然存在.

我检查了 localStorage、sessionStorage、cacheStorage、IndexedDB、cookie、但我没有找到我写的句子的实例.

另外,我检查了 Chrome Devtool 的网络选项卡,但没有发现任何可疑的网络流量.

github.com是如何实现这个恢复功能的?

解决方案

他们正在使用 SessionStorage 来做到这一点:

离开页面:

  1. 选择所有以 .js-session-resumable 作为选择器的输入字段
  2. 将 {id, value} 输入对放入数组中
  3. 将其放入 SessionStorage 作为 session-resume:/current/page/path

页面加载时:

  1. 检查 SessionStorage
  2. 中是否有任何带有 session-resume:/current/page/path 键的值
  3. 如果是,更新输入值并从 SessionStorage
  4. 中删除此记录

注意:如果你在一个页面中写了一条评论(没有提交它)然后转到另一个页面,那么你可以看到你的评论保存在SessionStorage中.p>

When I write a comment with github's issue page, I noticed that the comment body remains even if I reload the browser.

I have checked localStorage, sessionStorage, cacheStorage, IndexedDB, cookie, but I found no instance of the sentence that I wrote.

Also, I have checked the network tab of Chrome Devtool, but I could not find any suspicious network traffic.

How does github.com achieve this recovery function?

解决方案

They are using SessionStorage to do this:

On Page Leave:

  1. select all of the input fields with .js-session-resumable as selector
  2. put {id, value} pair of inputs in an array
  3. put it in SessionStorage as session-resume:/current/page/path

On Page Load:

  1. check if there are any values with session-resume:/current/page/path key in SessionStorage
  2. if yes, update values of inputs and remove this record from SessionStorage

Note: If you write a comment in a page (without submitting it) and go to another page, then you can see your comment saved in SessionStorage.

这篇关于github:即使重新加载浏览器也会留下评论,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆