-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix lazy reload for urls without index #1110
Fix lazy reload for urls without index #1110
Conversation
329c861
to
411b33c
Compare
cc1062a
to
3c106d8
Compare
@nbriannl could I get your review here? Aim of the changes here being to normalize |
3c106d8
to
5a69c47
Compare
If i understand correctly, Before this change, only http://127.0.0.1:8080/userGuide/index.html, would live reload? |
Yup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, works when I tested. But I think someone more experienced with this should approve
5a69c47
to
f041c7e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking at this :) just a suggestion from me
index.js
Outdated
return; | ||
} | ||
|
||
let normalizedUrl = req.url.replace(config.baseUrl, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use normalizedUrl
until L208. Could we define normalizedUrl
closer to it's usage?
Also, I generally prefer using const
and naming intermediate variables explicitly. I find that this makes it easier to follow what each step is doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch 😅, thanks! Updated some of the comments as well
f041c7e
to
bd21d45
Compare
index.js
Outdated
let normalizedUrl = req.url.replace(config.baseUrl, ''); | ||
|
||
// Map 'hostname/userGuide/' and 'hostname/userGuide' to hostname/userGuide/index. | ||
normalizedUrl = (hasNoExtension || hasEndingSlash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do:
const urlWithoutBase = ...
const urlWithIndex = ...
const urlWithoutExtension = ...
I think we should avoid mutation where possible. In this case, we can break this transformation down into individual independent steps with variables names that make each step self-explanatory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logical flow is fairly straightforward here, but in other more complex cases variable mutation can lead to some hard to trace errors. I have a strong preference for const
over let
whenever possible to avoid this, but I'm happy to discuss if you (or anyone else) has a different preference :)
index.js
Outdated
@@ -179,21 +179,42 @@ program | |||
|
|||
if (onePagePath) { | |||
const lazyReloadMiddleware = function (req, res, next) { | |||
const isHtmlFile = req.url.endsWith('.html'); | |||
const requestExtension = path.posix.extname(req.url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just extension
or urlExtension
is fine? 😛 req
itself is an object that has a bunch of other stuff in it, so requestExtension
doesn't feel very correct to me.
Lazy live reloading uses the file extension of the request url to determine whether the request is for a html page, and not from a dynamic include. Hence, requests for index.html with urls that do not end with index.html fail to be detected. Let’s add extra processing to detect such requests.
bd21d45
to
b33c554
Compare
Updated the variable naming |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :)
* 'master' of https://github.com/MarkBind/markbind: Fix lazy reload for urls without index (MarkBind#1110) Changes remaining references from filterTags to tags (MarkBind#1149)
…bind into remove-fixed-bugs * 'remove-fixed-bugs' of https://github.com/Tejas2805/markbind: Docs: Add contributing.md (MarkBind#1139) Show pointer and use underline dashed for click trigger (MarkBind#1111) Support variables to be defined as by JSON (MarkBind#1117) Allow an array for specifying page src or glob (MarkBind#1118) Code blocks: Implement inline markdown support for heading (MarkBind#1137) Fix lazy reload for urls without index (MarkBind#1110) Changes remaining references from filterTags to tags (MarkBind#1149)
Lazy live reloading uses the file extension of the request url to determine whether the request is for a html page, and not from a dynamic include. Hence, requests for index.html with urls that do not end with index.html fail to be detected. Let’s add extra processing to detect such requests.
What is the purpose of this pull request? (put "X" next to an item, remove the rest)
• [x] Bug fix
Fixes #1109
What is the rationale for this request?
To normalize url requests that reference
index.html
implcitly ( eghostname/userGuide
,hostname/userGuide/
), such that a page build is triggered ( if needed ).What changes did you make? (Give an overview)
Added some code to normalize urls that reference
index.html
implicitlyProvide some example code that this change will affect:
Is there anything you'd like reviewers to focus on?
na
Testing instructions:
lazy reload for urls that reference
index.html
implicitly ( eg.userGuide/
,userGuide
) should now correctly trigger a page build ( if necessary )Proposed commit message: (wrap lines at 72 characters)
Fix lazy reload for urls without index
Lazy live reloading uses the file extension of the request url to
determine whether the request is for a html page, and not from a
dynamic include.
Hence, requests for index.html with urls that do not end with
index.html fail to be detected.
Let’s add extra processing to detect such requests.