Skip to content

[Bug]: package_info_plus is not using the right URL to load the version.json file in web #2732

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

Closed
8 tasks done
AriasBros opened this issue Mar 19, 2024 · 3 comments · Fixed by #2733
Closed
8 tasks done
Labels
bug Something isn't working triage

Comments

@AriasBros
Copy link
Contributor

Platform

Any web browser

Plugin

package_info_plus

Version

5.0.1

Flutter SDK

3.7.0 and above

Steps to reproduce

Introduction

As of Flutter 3.7.0, Flutter allow us to pass an assetBase value when the Flutter web engine is initialized:

_flutter.loader.loadEntrypoint({
    entrypointUrl: "https://www.my-app-domain.com/app/main.dart.js"
    onEntrypointLoaded: async function(engineInitializer) {
        let appRunner = await engineInitializer.initializeEngine({
            assetBase: "https://www.my-app-domain.com/app/"
        });
        appRunner.runApp();
    }
});

This allow us to load the application from a domain my-business-domain.com when the application is actually deployed in other one my-app-domain.com

Bug

Having the next domains:

  • my-app-domain.com: Serving the app files domain
  • my-business-domain.com: Executing the app files domain

package_info_plus is failing because it is trying to load the file version.json using the second domain instead the first one

Other users are having the same issue: #1409 (comment)

The problem of this issue is here:

final url = versionJsonUrl(web.window.document.baseURI, cacheBuster);

Instead to get the base URI using some Flutter API, it is being fetched using a web specific API, which returns the URL used in that moment by the browser, what as we could see previously, that URL could not be where the Flutter app is actually deployed.

Code Sample

No response

Logs

NA

Flutter Doctor

NA

Checklist before submitting a bug

  • I searched issues in this repository and couldn't find such bug/problem
  • I Google'd a solution and I couldn't find it
  • I searched on StackOverflow for a solution and I couldn't find it
  • I read the README.md file of the plugin
  • I'm using the latest version of the plugin
  • All dependencies are up to date with flutter pub upgrade
  • I did a flutter clean
  • I tried running the example project
@AriasBros AriasBros added bug Something isn't working triage labels Mar 19, 2024
@miquelbeltran
Copy link
Member

miquelbeltran commented Mar 19, 2024

Would be providing an optional parameter in static Future<PackageInfo> fromPlatform() with the custom version.json url enough to bypass this issue?

Instead to get the base URI using some Flutter API

Does that exist? Can you provide more information?

@AriasBros
Copy link
Contributor Author

Instead to get the base URI using some Flutter API

Does that exist? Can you provide more information?

Hi @miquelbeltran,

I sent a PR (#2733) using the AssetManager to achieve the same result as the current implementation, but supporting in this way setups where the app is server from a different domain.

Flutter doesn't have a explicit public API to get this base URL, but with a little hack (using public API) it was possible to get it.

Would be providing an optional parameter in static Future<PackageInfo> fromPlatform() with the custom version.json url enough to bypass this issue?

If the current implementation sent in the PR is not valid or good, I can take a look to change to this approach.

@miquelbeltran
Copy link
Member

Thanks David! I replied in the PR

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working triage
Projects
None yet
2 participants