简体   繁体   English

React.js 我在 prod 中有 Bug,但在 dev 模式下没有,你能帮帮我吗

[英]React.js i have Bug in prod but not in dev mode, can you help me

I've been having a problem for 3 days now, and I don't really understand what can cause this bug, can you help me?我已经有3天的问题了,我真的不明白是什么导致了这个错误,你能帮我吗?

Here is the problem, I have created a small game(react.js) where 5 cards are displayed at each reload, these 5 cards have a score of points each which are cumulated each time, which gives a score of all the cards, then the score of each "hand" which is cumulated.这就是问题所在,我创建了一个小游戏(react.js),其中每次重新加载时显示 5 张卡片,这 5 张卡片每张都有一个分数,每次累积,这给出了所有卡片的分数,然后累积的每个“手”的分数。

In development mode, everything works correctly, but if I build and put it on a cdn (netlify), the score logic doesn't work...在开发模式下,一切正常,但如果我构建并将其放在 cdn (netlify) 上,则分数逻辑不起作用......

Prod link (bug) : https://are-you-lucky-game.netlify.app/产品链接(错误): https ://are-you-lucky-game.netlify.app/

Github repo link (dev mode work fine) : https://github.com/rodolphe37/random-playing-card-tuto/tree/step-3-final Github repo 链接(开发模式工作正常): https ://github.com/rodolphe37/random-playing-card-tuto/tree/step-3-final

I think the problem may be coming from over here:我认为问题可能来自这里:

In my console on render (in dev)在我的控制台上渲染(在开发中)

score: undefined
classment from ScoreForm {pts: 0, name: ''}
scoreArray (5) [3, 7, 10, 15, 2]
classment from center Page {pts: 0, name: ''}
classment from state {pts: 0, name: ''}
classment from session  {pts: 0, name: ''}

score: undefined
classment from ScoreForm {pts: 0, name: ''}
scoreArray (5) [3, 7, 10, 15, 2]
classment from center Page {pts: 0, name: ''}
classment from state {pts: 0, name: ''}
classment from session  {pts: 0, name: ''}

score: 0
classment from ScoreForm {pts: 37, name: ''}
score: 37

in dev, my component is rendered several times (3 or 4 i think), and at the last render, the info is there.在开发中,我的组件被渲染了几次(我认为是 3 或 4 次),并且在最后一次渲染时,信息就在那里。

In my Console (prod mode)在我的控制台中(产品模式)

score: undefined
classment from ScoreForm {pts: 0, name: ''}
scoreArray (5) [5, 25, 3, 6, 1]
classment from center Page {pts: 0, name: ''}
classment from state {pts: 0, name: ''}
classment from session  {pts: 0, name: ''}
score: 0
classment from ScoreForm {pts: 0, name: ''}``

In production, my component is rendered two time I think, so my values are not there.在生产中,我认为我的组件被渲染了两次,所以我的值不存在。

How can I make sure that my info (it comes from sessionStorage) is present at the first render of each component?如何确保我的信息(它来自 sessionStorage)出现在每个组件的第一次渲染中?

If you have ever encountered this kind of bug, or if you think you have a solution for me, I'm interested.如果您曾经遇到过这种错误,或者您认为您有适合我的解决方案,我很感兴趣。

Thanks in advance!提前致谢!

I can see in your repo that you are using browserslist in package.json This is common in react-create-app as this library will bundle your code based on the configuration that is provided.我可以在您的存储库中看到您在 package.json 中使用browserslist这在 react-create-app 中很常见,因为该库将根据提供的配置捆绑您的代码。 Notice that you have two different configurations for development and production, try using the same config you have in development also for producttion object, this should fix your issue.请注意,您有两种不同的开发和生产配置,请尝试将开发中的相同配置也用于生产对象,这应该可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM