-
Notifications
You must be signed in to change notification settings - Fork 210
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
Webpack support and minor bug fixes. #431
Webpack support and minor bug fixes. #431
Conversation
TODO Clean up the local ip flag Fix theme issues
…ng all js into one bundle
…ues with AppBar overflowing content
@KeiranHines Thanks for submitting this. Do I understand correctly that the main additional feature towards the end user is the persistence of tabs and theme across uses of the UI, and the other changes are more of a preparation for further development? While having a first look at the changes, I noticed that bake_site.py now depends on the presence of a UNIX-like shell. For the tools used in the main pio build flow, of which bake_site.py is one, we really want to retain functionality on non-UN*X systems (read: Windows) as well. That being a premise, I think the changes to bake_site.py need to be made in such a way that they are OS agnostic. Furthermore, we want to prevent (additional) dependencies where possible as well, as new dependencies increase the threshold for engaging with the codebase. The logic in the current bake_site.py was specifically written to prevent a dependency on a tool like npm, which you now (re)introduce. Do you think it would be reasonably possible to move forward with the UI development without doing this? |
@rbergen you are correct on the user facing features and development improvements. As for your comments. The changes are windows and nix compatible. I have compiled this on windows 11 with PowerShell. While I agree in principle additional dependencies shouldn't be added lightly. For front end development I feel this change is required, and most developers would expect to use npm for front-end work. I'll admit it took me a bit to work out how everything went together without it, especially lacking any imports between files. While I feel I could move forward with front-end development without the development changes, I feel it would be a disadvantage in development, especially managing imports between files and conflicts in the current system. Not to mention the lack of good development tooling without the changes. In my opinion this change would lower the barrier of entry of more front-end developers to engage with the code base. |
Okay, I think we may just have reached the point where using npm (or similar tooling) is inevitable. That said, we will have to:
|
Noted. I will update the readme and bake site script to inform developers what to install and provide helpful error messaging if not installed. On the subject of dependencies. Currently a yarn.lock file is used for version management, however installing yarn requires installing node/npm. I could migrate this to an npm package lock instead reducing the dependencies by one. Assuming the community was happy with using npm. |
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 don't speak react, so I have only the one concern in the C++ side.
FWIW, my primary development environment is MacOS these days and npm is already present in my homebrew installation, so that's probably not a problem the Mac users. The kind of MacOS user cross-compiling code like NightDriverLED -probably- already has Homebrew (or equiv) loaded and 'brew install npm' would be all that'd be needed if I understand the objection. I just don't perceive it as a speedbump.
Thanx for taking this on!
include/webserver.h
Outdated
Serial.printf("GET for: %s\n", strUri); | ||
AsyncWebServerResponse *response = request->beginResponse_P(200, file.type, file.contents, file.length); | ||
if (strnlen(file.encoding, 25) > 0) |
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 presence or absence of an encoding header depends on its LENGTH? That's odd.
If file.encoding is a plain ole C string, that's just guaranteed to not be null (and if it is, this is about to crash anyway) should it just be testing that the string isn't empty? i.e. if (file.encoding[0]) { ...
If there's more to it than that, please explain (in code, if appropriate, where that magic number "25" comes from.
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.
In principle I totally agree with defensive coding in general, and when handling C strings in particular. In line with what @robertlipe said, it is not necessary to be too defensive though. In this case, the entire EmbeddedWebFile
struct is private to the class this function is a member of. That means we can make some assumptions on the proper initialization of the instances that are created. I therefore agree that a simple check if the first character isnt '\0'
is enough.
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.
Updated to address this issue.
const httpPrefix = process.env.NODE_ENV === "development" ? "http://255.255.255.0" : undefined; |
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.
Yay! fewer hardcoded pathnames is a Good Thing.
Thanks @KeiranHines, I really appreciate that.
If we accept npm as a dependency, which we've just decided to do, then we can also use it to install other dependencies like yarn. If the automation embedded in our build tooling were to take care of "installing dependencies if not present" where needed (using npm where appropriate), I would not consider those dependencies additional prerequisites. Until you opened this PR, "the community" in the contributing sense was @Louis-Riel. He originally introduced the use of npm before removing the "hard dependency" on it by writing the first version of the bake_site.py script you'll now be modifying. |
Thanks for the info @rbergen. |
@KeiranHines All of that makes sense to me. Please proceed with the approach you think is best, everything considered. |
@rbergen @davepl I have updated the branch the changes to the readme to specify installing NPM, and a warning in the bake_site script. I have also included a switch from yarn.lock to package-lock.json to remove the requirement for yarn. As a side node. I have already worked on the legacy styling method mentioned in the description and have the bundle size down to 68K now. I will put that PR up after this one has been approved and merged. |
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 we're very nearly there! I have one comment that aligns with one @robertlipe already made and one question, see below.
include/webserver.h
Outdated
Serial.printf("GET for: %s\n", strUri); | ||
AsyncWebServerResponse *response = request->beginResponse_P(200, file.type, file.contents, file.length); | ||
if (strnlen(file.encoding, 25) > 0) |
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.
In principle I totally agree with defensive coding in general, and when handling C strings in particular. In line with what @robertlipe said, it is not necessary to be too defensive though. In this case, the entire EmbeddedWebFile
struct is private to the class this function is a member of. That means we can make some assumptions on the proper initialization of the instances that are created. I therefore agree that a simple check if the first character isnt '\0'
is enough.
Update: you can scratch the question, as I tested it myself. Builds on my (Windows) machine! |
…trip into feature/styled
… to load mui from a CDN reducing bundle size to 15K
@rbergen @davepl for the failing build. it looks like its simply the JS bundle being too large. I have already addressed this in another branch. https://github.com/KeiranHines/NightDriverStrip/tree/feature/styled. This updated branch drops the bundle size from the 81K it is here down to 15K. Which is clearly better than the ~50K it was before I started making changes. What would your preferred method for merging these changes in be? I didn't initially push them to this branch because I didn't want to merge too much code at once. But in the interest of getting the builds passing I can. |
@KeiranHines You're quick to respond to the failing build. :) I was just looking at it myself, and I noticed that OTA updates are disabled for the TTGO project, while it's using a partition scheme that caters for them. So, as far as I'm concerned we can do two things:
I'm basically fine with both approaches. In your opinion, is there a specific reason not to pull in your lined-up changes straight away? |
@rbergen the current stats are 27 files changed, +710, -887. It's mostly changing className={...} to sx={...} for changing the new styling APIs. As for the TTGo_noota, I think that change should be done either way if OTA isn't being used. |
As I said, I am okay with switching to the noota scheme for TTGO because that project doesn't currently have OTA enabled anyway, but making that switch does block (re)enabling OTA for TTGO at the partition level. If we can prevent that scenario by allowing another day (or two, if needs be) for you to complete the changes you're now working on, then personally I would prefer that. The change stats you shared don't make me nervous, so I'm happy to add those to this PR when you're ready to do so. |
@rbergen PR is updated again. Bundle size is now |
Thanks! Let's stick to the old partition scheme for TTGO though, if that project now builds with the OTA partition scheme and the new reduced bundle size. That way, people can choose to enable OTA with one small edit in globals.h, without having to go into editing platformio.ini (and figuring out its structure first). |
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.
If #594 in platform.ini actually changes the partition table for ttgo devices, this breaks their filesystem on upgrade, doesn't it? We've broken userdata and potentially just clobbered their active B partition, rendering it unbootable if that's the case.
Didn't we agree we can't be casually flipping around partition tables without code to preserve user data is bad?
It's crazy hard for me to read the inheritance of these scons files, but this change was made for a reason, so I assume we're changing it.
Rutger, how about all those whitespace changes?
We did, and this is precisely why I don't want to make this change unless it is the only way to get TTGO to build with the updated web UI.
The changed file count is identical with and without whitespace changes filtered. That means other things have changed as well, and then whitespace can go along - if that helps consistency in the modified code. Looking at the proposed changes, that seems to be the case. |
Thanks all. I have reverted the TTGO change. Sorry there was some confusion on my side with that one. |
That's ok, that's what reviews are for. :)
Generally speaking, whitespace isn't a Thing in the context of this project. Indentation should clarify the structure of the code it's applied to, and that's mainly it. That means that:
In this case I had already taken a closer look at the React side of things in your PR, and concluded it is not only actually a decently comprehensive overhaul of that code, but also a step-up to future changes that you've already indicated you want to work on. Furthermore, I agree that the changes that are made do clarify the structure of the code better than the old indentation did. |
@KeiranHines Just noting for the record that due to the magnitude of the change, I'll test this on the two devices I have available to me (Mesmerizer and M5StickC Plus) before moving forward towards merging. |
No worries @rbergen I expected someone would test it out. I have only noticed a few slight graphical changes. mostly stemming from css that was correctly applied previously. If you notice anything you'd consider unacceptable please let me know. |
@KeiranHines At this moment the main criterion is that we don't suffer any real functional regression. When the foundations for future development of the web UI are in place and you (and possibly others) start working on the web UI work items in the Issues list, then we can start being pickier about the "graphical details". I know Dave has stronger opinions about the appearance side of things than I do, but he's also not a proponent of optimizing too early. To a certain extent it's up to you (plural you, as in the web UI developers) to indicate when you need either:
However, first things first. I'll try my best to test this PR in my evening (it's 3PM for me when I write this). I'll let you know if I find anything that looks "out of order". |
Ok, I've tested this on both devices, and the web UI seems to work well. The persistence of configuration and theme works as advertized, and everything else that used to still does too. I did notice one thing, which is that package-lock.json seems to insist on wanting to lose the empty Could that be because I'm using a different version of npm (mine is 9.6.7) than you did while developing? |
…tency of pacakge lock between developers
@rbergen You are correct with package-lock. I have updated the repo now to use |
@KeiranHines Yes, that seems to have done the trick, thanks! I took the liberty of updating one comment in bake_site.py - the original version looked like an "unedited copy/paste" to me. If you're happy with that then I'm happy to merge this PR. |
Thanks @rbergen I am happy with that change. |
@KeiranHines Thank you very much for taking up the web UI challenge, and getting its development moving again! |
Description
Features added
Added usage of localStorage to store the configuration the user had when last using the UI.
Added support for Webpack. This enabled code to written cleaner as IDE support such as linting will now work.
/dist
directory under siteoffline
version of thesite
bundle. This allows the frontend code to be compiled without use of a CDN. This bundle is significantly larger and not recommended unless your devices will not have an active internet connection.Added support for eslint as a method of standardizing frontend styling. Usage of this configuration is optional.
Added a
.clang-format
file to allow autoformatting relatively close to the existing standards. Usage of clang-format is optional.Known limitations:
site
bundle size has increased from 56K to 81K. This is due to an issue with loading@mui
from a CDN in which the theme does not load. To address this migration from@mui/styles
should be done https://mui.com/system/styles/basics/. If this migration is completed. On the CDN loading was fixed the bundle size is estimated to be around 34KContributing requirements
main
as the target branch.