-
Notifications
You must be signed in to change notification settings - Fork 62
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: add support for non-root base-href #75
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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. |
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 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!
|
||
import 'package:web/web.dart'; | ||
import 'package:web/web.dart' as web; |
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.
Hell yeah, package:web powerrrrr!
wakelock_plus/lib/assets/no_sleep.js
Outdated
console.error(err.name + ', ' + err.message) | ||
_this2.nativeEnabled = false | ||
var errorMessage = err.name + ', ' + err.message | ||
console.error(errorMessage) |
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.
Try to limit the amount of console logging in the JS code, if possible. Since you're completing with an error, it might be better to log from Dart, so you can use things like if (kIsDebug)
to not log in production and stuff like that? (or not :P)
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'll comment out the logs if that makes things better.
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 it's fine that the plugin logs/warns on these recoverable errors, but I'd log from Dart, instead of JS.
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 removed the log. All the errors are passed via Promise.reject
or completeError
, so the user of the plugin can chose to handle and/or log them
if ((element as HTMLScriptElement).src.endsWith(url)) { | ||
if ((element as web.HTMLScriptElement).src.endsWith(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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. I hope the locking part works out as planned. These things are really hard to test. The happy path works though
@@ -6,13 +6,21 @@ import 'package:wakelock_plus/src/wakelock_plus_web_plugin.dart'; | |||
import 'package:wakelock_plus/wakelock_plus.dart'; | |||
import 'package:wakelock_plus_platform_interface/wakelock_plus_platform_interface.dart'; | |||
|
|||
/// | |||
/// Run these tests with: | |||
/// flutter run -d chrome test/wakelock_plus_web_plugin_test.dart |
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.
This is better than nothing, but super non-standard! If you want to run tests like this, I'd suggest you try to migrate them to flutter drive
, like what we did in flutter/packages, for example:
https://github.com/flutter/packages/tree/main/packages/video_player/video_player_web/example <- this "example" actually contains the integration_test
and all that jazz. The README.md should have some links to the docs on how to run those.
@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 <[email protected]>
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? |
Description
if a web-app is deployed using
--base-href=/path/to/deployed/flutter/app
during build, the URLs starting with./assets
won't work anymore. Using assetManager will properly resolve them. It usesassetBase
from 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