-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[flutter_tools] Add experimental path-based browser location handling for Flutter Web. #55232
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
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
We can't land this without tests. If you can find someone (or some time) to write tests in the near future, that would be great; otherwise we should probably close the PR until you have the time to write tests. |
449b022
to
a490bab
Compare
@Hixie Added tests |
a490bab
to
b8e306f
Compare
@@ -834,7 +862,7 @@ class ReleaseAssetServer { | |||
'Content-Type': mimeType, | |||
}); | |||
} | |||
if (request.url.path == '') { | |||
if (request.url.path == '' || enableIndexRewrite) { |
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.
Is there any downside to always returning the index.html here?
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 this is the only change needed for all this plumbing, it seems like it would be easiest to always return the index, especially if this becomes the default in the future
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 to make it optionally always return the index such that we don't break the previous behaviour.
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.
And it makes the release web server match the behaviour of the debug web server.
@@ -337,6 +352,12 @@ class WebAssetServer implements AssetReader { | |||
file = globals.fs.file(webPath); | |||
} | |||
|
|||
if (!file.existsSync() && enableIndexRewrite) { |
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.
Oh I see, this one too
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 handles the case if index.html is missing we return a 404.
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.
Can we tell the difference between a request to some/nav/path
and asset.jpg
? I would be okay with the former always returning index.html
in either mode, but the later should always be a 404
4563670
to
c643196
Compare
It does already prioritise the assets over the unknown paths. But no there is way to detect the different types of request. Because a route name can be anything including classed 'something.jpg' (if they wanted) |
Do you know how do other sorts of dev servers for web frameworks handle it? I'd rather not introduce drastically different behavior for these two modes. Even if the developer has opted into the path strategy, it seems unfriendly to return the index if they incorrectly specify an asset. |
Url rewrites on live servers works this way.. @passsy uses Firebase Hosting. |
Seems like a reasonable option would be to support rewrites on URLs without a file extension? |
JS tools like webpack solve this on the client side. Webpack has a config called publicPath (<-- this link has good documentation explaining how it works). Basically, the idea is that the app developer provides a Example: Let's say we have an app that's being served on |
For the "asset" assets, we essentially always use a baseUrl of I think it would be easier to think about this change if there were some examples of apps that worked with hash-based navigation that would otherwise break when switching to this to new strategy |
@jonahwilliams the main difference is that the hash path has no effect on request paths and the server doesn't receive the hash path. index.htmlWhen you reload this url: But with the new location strategy, you would be navigating to assetsUsing hash paths, when the user is on Using the new location paths, when the user is on
When I say assets, I mean anything that's loaded over the network (fonts, images, etc). Also, I'm not sure how this will affect service worker caching since it uses a relative path to cache, right @jonahwilliams? |
CC @johnpryan. |
c643196
to
1bb4a6f
Compare
… for Flutter Web. Added tests. Updated define name to: flutter.web.usePathStrategy
1bb4a6f
to
8044535
Compare
I spoke offline with @mdebbar and @yjbanov about the best way to handle this in the tool. We'd like to keep the behavior consistent in both modes, so lets do the fallback regardless of whether the flag was provided. Next, we want to ensure that we don't incorrectly fallback for assets that have typos. Since all assets should have |
For service worker changes, I can handle that as a follow up. |
@jonahwilliams what's happening with this? |
@slightfoot I asked for changes the comment #55232 (comment) There are also failing tests that need to be addressed |
@jonahwilliams I'd didn't realise that your statements were a request for change and they are a little unclear to me. I just want to restate to get clarification before edits.
Is that correct? |
Yes, that SGTM |
@slightfoot have you had a chance to look into the changes? |
Because of the lack of activity on this PR I'm going to close it to remove from our review queue. Please feel free to send us a new PR or discuss in an issue anytime. |
lack of activity means you can close PR's and throw away? interesting. |
@mehmetkose keeping the PR open with no activity increases the overhead for reviewers who go through the queue of open PRs. I assure you nothing is thrown away. The branch that contains the changes is still there. The author (or anyone else) can easily clone this PR when they have more time available. |
Any update on this ? |
Description
This enables the
flutter run
to start a local web-server that hosts index.html for unknown pages and thus allowing the Flutter Web JavaScript to detect the correct URL when using the new path location strategy.This patch depends on my other PR for the engine here: flutter/engine#17829
Example usage
flutter run -d chrome --dart-define=flutter.web.usePathStrategy=true
flutter run -d chrome --release --dart-define=flutter.web.usePathStrategy=true
flutter build web --dart-define=flutter.web.usePathStrategy=true
Related Issues
Closes: #33245 - Flutter_web navigation should provide a way to remove hash symbol(#)
Tests
Tests added.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read [Handling breaking changes].
/cc @jonahwilliams @yjbanov