Skip to content

Commit

Permalink
fix(preview): does not disconnect with same buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcco committed Oct 15, 2023
1 parent a79fc02 commit 0b38302
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/out/404.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html><head><meta charSet="utf-8" class="next-head"/><link rel="preload" href="/_next/static/dCpd5TMvi0q6amYeAEIE1/pages/404.js" as="script"/><link rel="preload" href="/_next/static/dCpd5TMvi0q6amYeAEIE1/pages/_app.js" as="script"/><link rel="preload" href="/_next/static/dCpd5TMvi0q6amYeAEIE1/pages/_error.js" as="script"/><link rel="preload" href="/_next/static/runtime/webpack-2ef50c24cc8d478adafc.js" as="script"/><link rel="preload" href="/_next/static/chunks/commons.eb02219a61ab5016dbbe.js" as="script"/><link rel="preload" href="/_next/static/runtime/main-3978781480e8c13aefab.js" as="script"/></head><body><div id="__next"><div data-reactroot="">404</div></div><script>__NEXT_DATA__ = {"props":{"pageProps":{}},"page":"/404","query":{},"buildId":"dCpd5TMvi0q6amYeAEIE1","nextExport":true};__NEXT_LOADED_PAGES__=[];__NEXT_REGISTER_PAGE=function(r,f){__NEXT_LOADED_PAGES__.push([r, f])}</script><script async="" id="__NEXT_PAGE__/404" src="/_next/static/dCpd5TMvi0q6amYeAEIE1/pages/404.js"></script><script async="" id="__NEXT_PAGE__/_app" src="/_next/static/dCpd5TMvi0q6amYeAEIE1/pages/_app.js"></script><script async="" id="__NEXT_PAGE__/_error" src="/_next/static/dCpd5TMvi0q6amYeAEIE1/pages/_error.js"></script><script src="/_next/static/runtime/webpack-2ef50c24cc8d478adafc.js" async=""></script><script src="/_next/static/chunks/commons.eb02219a61ab5016dbbe.js" async=""></script><script src="/_next/static/runtime/main-3978781480e8c13aefab.js" async=""></script></body></html>
<!DOCTYPE html><html><head><meta charSet="utf-8" class="next-head"/><link rel="preload" href="/_next/static/s7O4q0ISzv1r8jtwIkXLb/pages/404.js" as="script"/><link rel="preload" href="/_next/static/s7O4q0ISzv1r8jtwIkXLb/pages/_app.js" as="script"/><link rel="preload" href="/_next/static/s7O4q0ISzv1r8jtwIkXLb/pages/_error.js" as="script"/><link rel="preload" href="/_next/static/runtime/webpack-2ef50c24cc8d478adafc.js" as="script"/><link rel="preload" href="/_next/static/chunks/commons.eb02219a61ab5016dbbe.js" as="script"/><link rel="preload" href="/_next/static/runtime/main-3978781480e8c13aefab.js" as="script"/></head><body><div id="__next"><div data-reactroot="">404</div></div><script>__NEXT_DATA__ = {"props":{"pageProps":{}},"page":"/404","query":{},"buildId":"s7O4q0ISzv1r8jtwIkXLb","nextExport":true};__NEXT_LOADED_PAGES__=[];__NEXT_REGISTER_PAGE=function(r,f){__NEXT_LOADED_PAGES__.push([r, f])}</script><script async="" id="__NEXT_PAGE__/404" src="/_next/static/s7O4q0ISzv1r8jtwIkXLb/pages/404.js"></script><script async="" id="__NEXT_PAGE__/_app" src="/_next/static/s7O4q0ISzv1r8jtwIkXLb/pages/_app.js"></script><script async="" id="__NEXT_PAGE__/_error" src="/_next/static/s7O4q0ISzv1r8jtwIkXLb/pages/_error.js"></script><script src="/_next/static/runtime/webpack-2ef50c24cc8d478adafc.js" async=""></script><script src="/_next/static/chunks/commons.eb02219a61ab5016dbbe.js" async=""></script><script src="/_next/static/runtime/main-3978781480e8c13aefab.js" async=""></script></body></html>

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/out/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html><head><meta charSet="utf-8" class="next-head"/><title class="next-head"></title><link rel="shortcut icon" type="image/ico" href="/_static/favicon.ico" class="next-head"/><link rel="stylesheet" href="/_static/page.css" class="next-head"/><link rel="stylesheet" href="/_static/markdown.css" class="next-head"/><link rel="stylesheet" href="/_static/highlight.css" class="next-head"/><link rel="stylesheet" href="/_static/katex@0.15.3.css" class="next-head"/><link rel="stylesheet" href="/_static/sequence-diagram-min.css" class="next-head"/><script type="text/javascript" src="/_static/underscore-min.js" class="next-head"></script><script type="text/javascript" src="/_static/webfont.js" class="next-head"></script><script type="text/javascript" src="/_static/snap.svg.min.js" class="next-head"></script><script type="text/javascript" src="/_static/tweenlite.min.js" class="next-head"></script><script type="text/javascript" src="/_static/mermaid.min.js" class="next-head"></script><script type="text/javascript" src="/_static/sequence-diagram-min.js" class="next-head"></script><script type="text/javascript" src="/_static/katex@0.15.3.js" class="next-head"></script><script type="text/javascript" src="/_static/mhchem.min.js" class="next-head"></script><script type="text/javascript" src="/_static/raphael@2.3.0.min.js" class="next-head"></script><script type="text/javascript" src="/_static/flowchart@1.13.0.min.js" class="next-head"></script><script type="text/javascript" src="/_static/viz.js" class="next-head"></script><script type="text/javascript" src="/_static/full.render.js" class="next-head"></script><link rel="preload" href="/_next/static/dCpd5TMvi0q6amYeAEIE1/pages/index.js" as="script"/><link rel="preload" href="/_next/static/dCpd5TMvi0q6amYeAEIE1/pages/_app.js" as="script"/><link rel="preload" href="/_next/static/dCpd5TMvi0q6amYeAEIE1/pages/_error.js" as="script"/><link rel="preload" href="/_next/static/runtime/webpack-2ef50c24cc8d478adafc.js" as="script"/><link rel="preload" href="/_next/static/chunks/commons.eb02219a61ab5016dbbe.js" as="script"/><link rel="preload" href="/_next/static/runtime/main-3978781480e8c13aefab.js" as="script"/></head><body><div id="__next"><main data-theme=""><div id="page-ctn" contenteditable="false"><section class="markdown-body"></section></div></main></div><script>__NEXT_DATA__ = {"props":{"pageProps":{}},"page":"/","query":{},"buildId":"dCpd5TMvi0q6amYeAEIE1","nextExport":true};__NEXT_LOADED_PAGES__=[];__NEXT_REGISTER_PAGE=function(r,f){__NEXT_LOADED_PAGES__.push([r, f])}</script><script async="" id="__NEXT_PAGE__/" src="/_next/static/dCpd5TMvi0q6amYeAEIE1/pages/index.js"></script><script async="" id="__NEXT_PAGE__/_app" src="/_next/static/dCpd5TMvi0q6amYeAEIE1/pages/_app.js"></script><script async="" id="__NEXT_PAGE__/_error" src="/_next/static/dCpd5TMvi0q6amYeAEIE1/pages/_error.js"></script><script src="/_next/static/runtime/webpack-2ef50c24cc8d478adafc.js" async=""></script><script src="/_next/static/chunks/commons.eb02219a61ab5016dbbe.js" async=""></script><script src="/_next/static/runtime/main-3978781480e8c13aefab.js" async=""></script></body></html>
<!DOCTYPE html><html><head><meta charSet="utf-8" class="next-head"/><title class="next-head"></title><link rel="shortcut icon" type="image/ico" href="/_static/favicon.ico" class="next-head"/><link rel="stylesheet" href="/_static/page.css" class="next-head"/><link rel="stylesheet" href="/_static/markdown.css" class="next-head"/><link rel="stylesheet" href="/_static/highlight.css" class="next-head"/><link rel="stylesheet" href="/_static/katex@0.15.3.css" class="next-head"/><link rel="stylesheet" href="/_static/sequence-diagram-min.css" class="next-head"/><script type="text/javascript" src="/_static/underscore-min.js" class="next-head"></script><script type="text/javascript" src="/_static/webfont.js" class="next-head"></script><script type="text/javascript" src="/_static/snap.svg.min.js" class="next-head"></script><script type="text/javascript" src="/_static/tweenlite.min.js" class="next-head"></script><script type="text/javascript" src="/_static/mermaid.min.js" class="next-head"></script><script type="text/javascript" src="/_static/sequence-diagram-min.js" class="next-head"></script><script type="text/javascript" src="/_static/katex@0.15.3.js" class="next-head"></script><script type="text/javascript" src="/_static/mhchem.min.js" class="next-head"></script><script type="text/javascript" src="/_static/raphael@2.3.0.min.js" class="next-head"></script><script type="text/javascript" src="/_static/flowchart@1.13.0.min.js" class="next-head"></script><script type="text/javascript" src="/_static/viz.js" class="next-head"></script><script type="text/javascript" src="/_static/full.render.js" class="next-head"></script><link rel="preload" href="/_next/static/s7O4q0ISzv1r8jtwIkXLb/pages/index.js" as="script"/><link rel="preload" href="/_next/static/s7O4q0ISzv1r8jtwIkXLb/pages/_app.js" as="script"/><link rel="preload" href="/_next/static/s7O4q0ISzv1r8jtwIkXLb/pages/_error.js" as="script"/><link rel="preload" href="/_next/static/runtime/webpack-2ef50c24cc8d478adafc.js" as="script"/><link rel="preload" href="/_next/static/chunks/commons.eb02219a61ab5016dbbe.js" as="script"/><link rel="preload" href="/_next/static/runtime/main-3978781480e8c13aefab.js" as="script"/></head><body><div id="__next"><main data-theme=""><div id="page-ctn" contenteditable="false"><section class="markdown-body"></section></div></main></div><script>__NEXT_DATA__ = {"props":{"pageProps":{}},"page":"/","query":{},"buildId":"s7O4q0ISzv1r8jtwIkXLb","nextExport":true};__NEXT_LOADED_PAGES__=[];__NEXT_REGISTER_PAGE=function(r,f){__NEXT_LOADED_PAGES__.push([r, f])}</script><script async="" id="__NEXT_PAGE__/" src="/_next/static/s7O4q0ISzv1r8jtwIkXLb/pages/index.js"></script><script async="" id="__NEXT_PAGE__/_app" src="/_next/static/s7O4q0ISzv1r8jtwIkXLb/pages/_app.js"></script><script async="" id="__NEXT_PAGE__/_error" src="/_next/static/s7O4q0ISzv1r8jtwIkXLb/pages/_error.js"></script><script src="/_next/static/runtime/webpack-2ef50c24cc8d478adafc.js" async=""></script><script src="/_next/static/chunks/commons.eb02219a61ab5016dbbe.js" async=""></script><script src="/_next/static/runtime/main-3978781480e8c13aefab.js" async=""></script></body></html>
17 changes: 12 additions & 5 deletions app/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default class PreviewPage extends React.Component {

this.preContent = ''
this.timer = undefined
this.bufnr = -1;

this.state = {
name: '',
Expand Down Expand Up @@ -111,11 +112,13 @@ export default class PreviewPage extends React.Component {
}

startSocket(bufnr) {
// Close the previous socket
if (window.socket) {
window.socket.close()
window.socket = undefined
if (this.bufnr === bufnr) {
return;
}
this.bufnr = bufnr;

// Close the previous socket
const tmpSocket = window.socket

window.history.replaceState(null, '', `/${bufnr}`)

Expand All @@ -138,10 +141,14 @@ export default class PreviewPage extends React.Component {
socket.on('close_page', this.onClose.bind(this))

socket.on('change_bufnr', this.onChangeBufnr.bind(this))

if (tmpSocket) {
tmpSocket.close()
}
}

componentDidMount() {
this.startSocket(window.location.pathname.split('/')[2])
this.startSocket(parseFloat(window.location.pathname.split('/')[2]))
}

onConnect() {
Expand Down
1 change: 1 addition & 0 deletions app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ exports.run = function () {
async function openBrowser ({ bufnr }) {
const combinePreview = await plugin.nvim.getVar('mkdp_combine_preview')
if (combinePreview && Object.values(clients).some(cs => cs.some(c => c.connected))) {
logger.info(`combine preview page: `, bufnr)
Object.values(clients).forEach(cs => {
cs.forEach(c => {
if (c.connected) {
Expand Down

0 comments on commit 0b38302

Please sign in to comment.