Skip to content

Handle baseUrl in live-preview reload check#1594

Merged
ang-zeyu merged 1 commit into
MarkBind:masterfrom
ryoarmanda:live-preview-handle-baseurl
Jun 21, 2021
Merged

Handle baseUrl in live-preview reload check#1594
ang-zeyu merged 1 commit into
MarkBind:masterfrom
ryoarmanda:live-preview-handle-baseurl

Conversation

@ryoarmanda

@ryoarmanda ryoarmanda commented Jun 19, 2021

Copy link
Copy Markdown
Contributor

What is the purpose of this pull request?

  • Documentation update
  • Bug fix
  • Feature addition or enhancement
  • Code maintenance
  • Others, please explain:

Resolves #1583

The problem lies on a mismatch between the HTTP-request routine and the filesystem-watch routine in the live-server patch. During HTTP-request, the URLs - which is used to identify WebSocket clients - actually include the baseUrl, while during the filesystem-watch, the filepaths of changed files do not. Thus, reloads are unable to be triggered due to lack of baseUrl.

The solution is to bring the baseUrl information to the patch. Fortunately, we have this information in our mount property of the server configuration, which is used to route paths prefixed by baseUrl to serve files from the _site directory.

For convenience and simplicity for MarkBind use, we now identify WebSocket clients by its normalized url, that is the url without the baseUrl. That way, when MarkBind calls LiveServer.getActiveUrls(), it will receive urls without needing further processing of removing the base url.

Overview of changes:

  • live-server patch
    • Added baseUrl property to the server object
    • Added baseUrl initialization during mount rule application
    • Modified socket-establishment routine to normalize the request url and record it as the identifier for the active tab

Anything you'd like to highlight / discuss:
Review of the general approach is appreciated.

Testing instructions:
Test these on the default site (markbind init), with defined and empty baseUrl property in site.json:

  1. Visit a page: it should be reloading promptly after page is built
  2. Edit the currently viewed page: recently viewed pages list should be properly reflected and changes should be promptly displayed

Proposed commit message: (wrap lines at 72 characters)
Handle baseUrl in live-preview reload check

In live-preview, checks are implemented to only reload pages that
correspond to the changed file. However, the comparison used for the
check has not taken into account the base url of the site, which
causes these checks to always fail and thus pages are not automatically
reloaded.

Let's add base url handling to the check, so that sites with specified
can properly benefit from the live-preview feature.


Checklist: ☑️

  • Updated the documentation for feature additions and enhancements
  • Added tests for bug fixes or features
  • Linked all related issues
  • No blatantly unrelated changes
  • Pinged someone for a review!

@ang-zeyu ang-zeyu merged commit 62bebd2 into MarkBind:master Jun 21, 2021
@damithc

damithc commented Jun 27, 2021

Copy link
Copy Markdown
Contributor

Thanks for the quick fix @ryoarmanda 👍

@ang-zeyu ang-zeyu added this to the 3.0.3 milestone Jun 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Live preview shows spinner instead of new content

3 participants