Skip to content
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

baseUrl has the wrong value because app path has "/test/" in it #1965

Open
mdebbar opened this issue Feb 15, 2023 · 8 comments
Open

baseUrl has the wrong value because app path has "/test/" in it #1965

mdebbar opened this issue Feb 15, 2023 · 8 comments
Assignees
Labels
area-web customer-flutter package:dwds type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@mdebbar
Copy link

mdebbar commented Feb 15, 2023

Here is the relevant code that was copied to dwds. Here is the code in dwds:

const _baseUrlScript = '''
var baseUrl = (function () {
// Attempt to detect --precompiled mode for tests, and set the base url
// appropriately, otherwise set it to '/'.
var pathParts = location.pathname.split("/");
if (pathParts[0] == "") {
pathParts.shift();
}
if (pathParts.length > 1 && pathParts[1] == "test") {
return "/" + pathParts.slice(0, 2).join("/") + "/";
}

We got a report from a user seeing this issue (and I was able to reproduce it, too): flutter/flutter#116360 (comment)

Basically, their app has a path "/sample_item/test/", it trips the generated bootstrap code into thinking that it's in test mode, and it calculates the wrong baseUrl.

@jakemac53
Copy link
Contributor

I didn't think flutter was still using build_web_compilers?

@mdebbar
Copy link
Author

mdebbar commented Feb 15, 2023

I didn't think flutter was still using build_web_compilers?

Hmmm.. I'm not sure. We do generate main_module.bootstrap.js here:
https://github.com/flutter/flutter/blob/dff09558d3fa6fa22253708df5072fbed9c656c9/packages/flutter_tools/lib/src/web/bootstrap.dart#L154

But when the file gets served by the web server, I see more content appended to the file. That extra content is exactly the same as this var baseUrl = ... in build_web_compilers. I also see code from here being appended.

I don't see a direct dependency on build_web_compilers here. Is it possible that this dependency is being pulled transitively? Or DDC uses it internally?

Note: This only happens in debug mode (using DDC).

cc @jonahwilliams who may have some extra context.

@jonahwilliams
Copy link
Contributor

We don't use build_web_compilers, but some of the flutter tool code was taken from bwc initially

@jakemac53
Copy link
Contributor

Ok, so probably the fix needs to be in the flutter tool code which was originally taken from bwc. I am not really sure what the right fix is here, or if that logic is even relevant for flutter web.

@jakemac53
Copy link
Contributor

I don't think I am going to bother fixing it in bwc unless somebody files an issue as I think this is probably pretty uncommon.

@mdebbar mdebbar transferred this issue from dart-lang/build Feb 15, 2023
@mdebbar mdebbar added package:dwds type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Feb 15, 2023
@mdebbar
Copy link
Author

mdebbar commented Feb 15, 2023

Thanks @jakemac53 and @jonahwilliams. I transferred the issue to the webdev repo (where dwds lives).

@annagrin
Copy link
Contributor

@mdebbar thanks for filing the issue! I'll take a look.

@lrsvmb
Copy link

lrsvmb commented Feb 28, 2024

Can confirm this is still happening with:

  • flutter: v3.2.4
  • js: v0.6.7
  • web: v0.4.2
  • web_socket_channels: v2.4.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web customer-flutter package:dwds type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants