我已经编码PWA已有大约一个星期了,我需要一些帮助,以了解为什么代码在Opera中完全有效,而在Safari中不起作用。
如何复制我的问题:
- 打开我的项目( link> link ) )和Opera(或Chrome或其他任何)
- 单击左侧的第三个按钮,
- 一旦做饭,就做饭(随机做一些随机的东西),然后注意切换打开并打开它。
- 重新加载页面,看看餐点仍然显示出来,但切换不会显示Safari。
- 由于某种原因,它在Safari中不起作用,
我是在使用Safari中不允许的代码吗?我如何解决这个问题?
我还通过firebase 在这里
I have been coding my PWA for about a week now and I need some help finding out why the code works completely in Opera, but not in Safari.
How to replicate my issue:
- Open my project (link) in both Safari (on mac or iphone or whatever) and Opera (or chrome or whatever)
- Click the 3rd button from the left and make a meal (make some random stuff up)
- Once you have made the meal, then notice the toggle switch and switch it on.
- Reload the page and see that the meal still shows but the toggle doesn't show for safari.
- It doesn't work in Safari for some reason
Am I using code that shouldn't be allowed in Safari or something? How do I work around this?
I have deployed a link as well to the site via firebase here
发布评论
评论(1)
在对不和谐进行了一些调试之后,我们发现在
script.js
中,这些行引起了问题:https://github.com/rohilpatel1/calebra/blob/78b13a86859c90d1897a6d9865e37124db636db636d58/script.jscript.jspript.js#l77
“ Safari,
e.target.parentnode.parentnode.innertext
与已保存的LocalStorage相比,有一个尾随空间:这意味着
a.name == e.target.parentnode.parentnode.innode.innertext.innertext.trim()永远不会满足,因此
userdata.mealInformation.find(a => a.name ==== e.target.parentnode.parentnode.innertext)
返回未定义,扔undefined不是对象
错误,导致切换似乎不更改。解决方案
是什么意思是我们必须修剪
e.target.parentnode.parentnode.innertext
:所以这不是局部通讯问题,只是代码问题
After some debugging on discord, we found that in
script.js
, these lines were causing the issue:Github
Error
What was happening was that somehow, in safari,

e.target.parentNode.parentNode.innerText
had a trailing space compared to the saved localStorage result:This meant that
a.name == e.target.parentNode.parentNode.innerText.trim()
was never satisfied, and souserData.mealInformation.find(a => a.name == e.target.parentNode.parentNode.innerText)
returns undefined, throwing anundefined is not an object
error, causing the toggle to appear not to change.Solution
What this means was that we had to trim
e.target.parentNode.parentNode.innerText
:So this wasn't a localStorage issue, just a code issue