Skip to content

Fix flutter web app not respecting assets path when in non-root folder#96774

Merged
fluttergithubbot merged 3 commits intoflutter:masterfrom
nicolasvac:master
Mar 10, 2022
Merged

Fix flutter web app not respecting assets path when in non-root folder#96774
fluttergithubbot merged 3 commits intoflutter:masterfrom
nicolasvac:master

Conversation

@nicolasvac
Copy link
Contributor

@nicolasvac nicolasvac commented Jan 18, 2022

This pull request aims to fix #68449.
This bug is blocking the incremental integration of every flutter web-app in subdirectories for existing systems.
And also, because this bug makes every flutter web-app search in the root domain path for assets, it only allows for one flutter web-app to co-exists even if in different projects / directories.

List which issues are fixed by this PR. You must list at least one issue.

If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jan 18, 2022
@flutter-dashboard
Copy link

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.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@nicolasvac nicolasvac changed the title Temporary Fix #68449 Fix #68449 Jan 18, 2022
@nicolasvac
Copy link
Contributor Author

I'm not sure where to look for writing a test or even how to, so if the PR reviewer could guide me that would help a lot.

@nicolasvac nicolasvac changed the title Fix #68449 Fix flutter web app not respecting assets path when in non-root folder Jan 18, 2022
Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this issue!

This looks good to me but I would like to have @yjbanov take a look too.

@mdebbar mdebbar requested a review from yjbanov January 18, 2022 20:46
@yjbanov
Copy link
Contributor

yjbanov commented Jan 20, 2022

The change itself LGTM. Is there a way to write a test that would make sure we don't break it in the future?

@yjbanov
Copy link
Contributor

yjbanov commented Jan 20, 2022

@nicolasvac
Copy link
Contributor Author

@yjbanov i think a test that checks if the '/' is present at the beginning of the file names is sufficient ?

Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, let's just remove this line. For the deployment scenarios that we formally support and already have tests for this line is unnecessary. However, it's worth fixing for other environments, even if we don't have a proper setup for replicating them in our tests. So I think a no-test exception is reasonable in this case.

lgtm

@yjbanov
Copy link
Contributor

yjbanov commented Feb 2, 2022

Of course, since we don't have a test environment that replicates Github pages or similar, there's no guarantee that we won't break this again in the future. We won't break it on purpose though.

Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, webworkers should be scoped to the directory from where they're served, so this "/" should mean: "/baseDir/" and not the root directory of the domain itself.

See Parameters > options > scope: https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#parameters

Let's try this, but I think that if we remove this, we're breaking the offline mode for the "root" of the webapp.

Also, the restriction above can be removed by the server via a header, so maybe this is a matter of the serviceworker being misconfigured?:

"Servers can remove this restriction by setting a Service-Worker-Allowed header on the service worker script, and then you can specify a max scope for that service worker above the service worker's location."

@ditman
Copy link
Member

ditman commented Feb 2, 2022

(Just checked in the original issue, and the headers are not overriding service worker scopes, odd)

@yjbanov
Copy link
Contributor

yjbanov commented Feb 2, 2022

For some reason I thought index.html was not served from the service worker in offline mode (or any mode), but maybe I'm wrong.

@yjbanov
Copy link
Contributor

yjbanov commented Feb 2, 2022

Well, our service worker does fetch it, but maybe that's unnecessary? We don't really support offline mode very easily right now, so all this may be a little moot.

@ditman
Copy link
Member

ditman commented Feb 2, 2022

(I think this can be merged, but it'll need revisiting when solving the issue you linked for sure @yjbanov)

@christopherfujino
Copy link
Contributor

@nicolasvac looks like there's a type error that the Linux web_long_running_tests_1_5 CI step is catching:

Unhandled exception:
type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<Object, Object>' of 'other'
#0      MapMixin.addAll (dart:collection/maps.dart)
#1      addStateInfo (package:matcher/src/util.dart:29:14)
#2      _DeepMatcher.matches (package:matcher/src/equals_matcher.dart:261:5)
#3      expect (file:///b/s/w/ir/x/w/flutter/dev/bots/service_worker_test.dart:61:15)
#4      runWebServiceWorkerTest.expectRequestCounts (file:///b/s/w/ir/x/w/flutter/dev/bots/service_worker_test.dart:76:5)
#5      runWebServiceWorkerTest (file:///b/s/w/ir/x/w/flutter/dev/bots/service_worker_test.dart:137:5)
<asynchronous suspension>
#6      _runShardRunnerIndexOfTotalSubshard (file:///b/s/w/ir/x/w/flutter/dev/bots/test.dart:1931:5)
<asynchronous suspension>
#7      _runWebLongRunningTests (file:///b/s/w/ir/x/w/flutter/dev/bots/test.dart:1115:3)
<asynchronous suspension>
#8      _runFromList (file:///b/s/w/ir/x/w/flutter/dev/bots/test.dart:1973:5)
<asynchronous suspension>
#9      main (file:///b/s/w/ir/x/w/flutter/dev/bots/test.dart:200:5)
<asynchronous suspension>

https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8824686530296893649/+/u/run_test.dart_for_web_long_running_tests_shard_and_subshard_1_5/test_stderr

@nicolasvac
Copy link
Contributor Author

@christopherfujino how is this affected by removing the first element of the list, considering it's still a list ?

@christopherfujino
Copy link
Contributor

@christopherfujino how is this affected by removing the first element of the list, considering it's still a list ?

I didn't actually look at your PR before. Now that I did...I have no idea

@christopherfujino
Copy link
Contributor

I scheduled a re-run of Linux web_long_running_tests_1_5. If that also fails, I would suggest rebasing upstream, in case this was something that has already been fixed in master.

@nicolasvac
Copy link
Contributor Author

@christopherfujino merged commits

@christopherfujino
Copy link
Contributor

I'm stumped on this failure, gonna ask about it on the tests channel of our discord server.

@christopherfujino
Copy link
Contributor

Ok, narrowed it down to an bug in the test file: #99522. I will submit a patch to fix.

@christopherfujino
Copy link
Contributor

Fix is in #99524

@christopherfujino
Copy link
Contributor

Fix is in #99524

Fix has been merged, @nicolasvac please rebase upstream. The test will still fail because you need to update an expectation, but the failure should tell you how to fix it.

@nicolasvac
Copy link
Contributor Author

@christopherfujino i've remerged everything and waited for the tests to run,
[CHROME STDERR]:Fontconfig warning: "/etc/fonts/fonts.conf", line 100: unknown element "blank" [CHROME STDERR]:

Still this is not related to this merge request. I hope this can be merged now as it has been over two months for "outside" problems

@christopherfujino
Copy link
Contributor

@christopherfujino i've remerged everything and waited for the tests to run, [CHROME STDERR]:Fontconfig warning: "/etc/fonts/fonts.conf", line 100: unknown element "blank" [CHROME STDERR]:

Still this is not related to this merge request. I hope this can be merged now as it has been over two months for "outside" problems

Per the Flutter team's Tree Hygiene policy this change cannot be merged with failing tests.

The customer_testing-linux test will be fixed by rebasing (not merging) upstream. As for the web test infrastructure failure, I am not familiar with that. I would recommend joining the discord #hackers-infra channel and following up there (alternatively you can file an issue for it).

@mdebbar
Copy link
Contributor

mdebbar commented Mar 7, 2022

The failures seem unrelated to this PR and are probably caused by the branch being stale.

@nicolasvac could you please try rebasing your branch on top of flutter:master to see if that fixes the failures? You may need to remove the merge commits before attempting to rebase.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 15, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flutter_tools][web] PWA ServiceWorker breaks on GitHub Pages (rootPath rewrite issue with url-params?)

6 participants