我一直在使用react-snapshot对我的站点进行服务器端呈现。我正在生产中使用它,但不在本地主机上使用。我使用它,以便在我的产品页面中注入我的元关键字/描述。
今天,我通过LiveChat组件添加了一个LiveChatInc机器人(来自LiveChatInc)。执行工作很简单:
import LiveChat from 'react-livechat';
<LiveChat license={1234567} /> 这似乎在我的本地主机上工作得很好(在这里我没有使用react快照),但在我的生产站点上却没有。当我将react-snapshot从生产中删除时,它工作得很好。
错误
因此,看起来上面的代码除其他代码外,还添加了以下一行:
<script src="https://secure.livechatinc.com/licence/null/v2/get_dynamic_config.js"></script>从这一行可以看出,许可证是null。所以,我猜是react-snapshot阻止了这个代码<LiveChat license={1234567} />从LiveChat获取正确的代码。
另一种实现方法是在</body>标记附近插入以下代码。但是这种方法也会产生同样的错误。
<!-- Start of LiveChat (www.livechatinc.com) code -->
<script type="text/javascript">
window.__lc = window.__lc || {};
window.__lc.license = 1234567;
(function() {
var lc = document.createElement('script'); lc.type = 'text/javascript'; lc.async = true;
lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc.com/tracking.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(lc, s);
})();
</script>
<noscript>
<a href="https://www.livechatinc.com/chat-with/1234567/" rel="nofollow">Chat with us</a>,
powered by <a href="https://www.livechatinc.com/?welcome" rel="noopener nofollow" target="_blank">LiveChat</a>
</noscript>
<!-- End of LiveChat code -->解决方案
所以我终于把这个搞定了。实际上,我尝试了几种预呈现解决方案(react快照、react snap、react static),但它们都没有正确实现react-livechat。于是我开始想,也许这就是我实现它的方式。但是,我根据文档实现了它,所以我真的不知道为什么它不起作用。我最后所做的就是将react-loadable作为这样的工具:
const LoadableLiveChat = Loadable({
loader: () => import('react-livechat'),
loading: () => '<div>Loading</div>'
});
<LoadableLiveChat license={1234567} />谢谢。
发布于 2019-08-29 10:28:31
您能给一个链接到您的暂存区或类似的东西,您已经部署(和破坏)版本与反应快照使用?很难给出任何建议而不看到这种设置“在行动中”。
https://stackoverflow.com/questions/57701088
复制相似问题