fix: add support for non-root base-href#75
Conversation
if a web-app is deployed using `--base-href` during build, the URLs starting with `./assets` won't work anymore. Use `assetManager` to properly resolve them
There was a problem hiding this comment.
@holzgeist Before I run the workflow, there is one thing that I need you to do.
In other words, we need to move assets/no_sleep.js into the lib folder as per this StackOverflow post. Eventually, it'll be under wakelock_plus/lib/assets/no_sleep.js. The reason being is that it should be moved there so that it's in line with how every other library exposes assets to its users.
You'll also have to modify the existing asset entry in pubspec.yaml so that it points to packages/assets/wakelock_plus/assets/no_sleep.js.
|
@holzgeist Please let me know if you're still gonna work on this change. Otherwise, I can commandeer it for you and take it to the finish line. Thanks. |
|
Hi @diegotori , thanks for the feedback. I'm going to work on it, probably today, maybe tomorrow |
|
@diegotori actually I need to solve some other issues before I have a working web-build to test this one. If you could commandeer this, it would be great, thanks 🙏 |
…ed to when its added to the registrar.
|
@holzgeist please verify the fixes made to this PR. I was able to do a bit of cleanup and/or fixes. Thanks. |
…a script element.
…hat it awaits asynchronous calls from the various wakelock related callbacks. As a result, the Dart layer no longer needs to manually await before calling WakelockPlus.enabled.
|
@holzgeist If you have an angle on the latest @ditman the above also applies to you as well, if you're able to review the JS changes that I made. Thanks. |
ditman
left a comment
There was a problem hiding this comment.
I left some comments, but I'm not an actual owner of the plugin, so please, take/ignore as you please from my comments.
Thanks for getting this fix over the finish line, and apologies for the delay in the review, it took me a long while to see this notification!
| if ((element as HTMLScriptElement).src.endsWith(url)) { | ||
| if ((element as web.HTMLScriptElement).src.endsWith(url)) { |
There was a problem hiding this comment.
I know this change is unrelated, but consider adding an id attribute to your script element, that way this method can be simplified to:
return head.querySelector('#$idForScriptElement') != null;You may need to keep a small map of urls to each of its idForScriptElement String (probably it'll only contain a single element?)
There was a problem hiding this comment.
done. I hope the locking part works out as planned. These things are really hard to test. The happy path works though
|
@diegotori thanks for working on this. But unfortunately this grew way outside of my comfort zone wrt flutter/web so I have to pass on reviewing this 🙈 |
Co-authored-by: David Iglesias <ditman@gmail.com>
Thanks for reviewing this. Since you have a better handle on the JS side of things, I'll let you take point on what I should modify. Feel free to call out more things as you see them. |
|
Hi there! |
|
ok, thanks to @ditman 's super detailed review and suggestions I actually was able to understand everything that's going on and apply the suggestions (apart from testing). They definitely all look and feel like improvements, thanks again for the through review 🙏 @diegotori @ditman any thoughts? |
|
@holzgeist I'll definitely take a look hopefully this week. Thanks for your contributions thus far. |
|
@holzgeist so far, it LGTM. @ditman, any thoughts on his changes? |
ditman
left a comment
There was a problem hiding this comment.
Never meant to block this code, thanks for all the improvements!
I don't have time to actually run this code, but if users and CI are happy with it, I don't have much more to say! :)
LGTM!
I got an "undefined" error in the catch branch. The only way this should be possible if registering a listener fails.
|
I added a commit to prevent _nativeEnabledCompleter from being null in the catch branch. Since then I realized that I had two requests running in parallel which interfered with each other. I'll still leave the commit there because it doesn't hurt :) |
|
I'm needing this as well. Any progress on it? |
|
@ditman looks like Not sure what you guys do over there to handle that situation. If you're able to shed some light on the current |
|
@holzgeist and @ditman thanks again for your input on this PR. This will get merged and deployed very shortly. |
|
@diegotori thanks for pushing this all the way through! This has been a long time coming :)
I was checking your command-line arguments to And here's where the code is actually run: (Same file, it's... big) Anyway, the only difference I see is that the infra is different, you use github actions but flutter/plugins uses google's LUCI infra. Our tests are pinning the flutter version and the Chrome version (not sure if that makes a difference in this particular case). In my experience, I've seen tests hang in Chrome when things don't complete, or something odd happens. Have you tried to run a super lame integration test in chrome that doesn't have any async code (literally just "expect(true, isTrue / isFalse)" or similar) to verify whether your issue is in the infra, or in the test itself? Debugging hanging drive tests is a bit of a chore, I normally comment out most of the test until I get to the conflictive line(s), and work from there. I've been affected many times by tests that |
Description
if a web-app is deployed using
--base-href=/path/to/deployed/flutter/appduring build, the URLs starting with./assetswon't work anymore. Using assetManager will properly resolve them. It usesassetBasefrom the loader config specified hereNB⚠️
I only tested the
url.startsWith('assets/')code path as it's the only one used in the library. It should work the same for./though