Closed stevebeauge closed 1 year ago
Hello stevebeauge, thank you for opening an issue with us!
I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback π
@stevebeauge thanks so much for reporting this. To be honest with you using our components in a browser extension wasn't on my radar at all, so that's a really cool use case that we had no samples or test cases for.
I'm really sorry this is breaking your extension, thank for the repro, it illustrates the issue nicely. One more thing you could do to help us out here, do you know of a way to attach a debugger to the extension, say in VSCode, or really any mechanism of having a debugger open and attached before opening the UI pane of the extension?
Not being able to attach before the issue occurs makes investigating the issue a challenging one to investigate.
@gavinbarron : I'm not used to open webpages with VSCode debugger open.
However, extensions are pages hosted on url like extension://mknmhhfclkaeokpkbihchgghfclaobdl/popup.html
(id will be path dependent) and follow, I guess, the same rules than any other page in term of lifecycle.
That means you may be able to put breakpoints wherever you want and "refresh" the page with devtools opened.
Side note though, if you use any "devtools" extension (I had the issue with griffel devtools and react devtools), the devtool extension won't be able to access other extension page, unless a specific flag is set in the browser AND the devtools extension whitelist your extension (which is quite exclusive).
Just run pnpm run dev
on a terminal to have the dev build version of the extension
I worked out that if I inspected the popup, set a breakpoint and used the console to run location.reload();
I could debug the point that the exception is thrown from.
After a little testing and found that just using a bare fluent-button also has the incorrect behavior too, it's my belief that this defect is in the button coming from the @microsoft/fast-foundation
package.
I'll submit an issue over there shortly.
Reproduction with code changed to use a fluent-button only https://github.com/gavinbarron/repro-fluent-button-plasmo
Hi @stevebeauge
I've done some more digging with some help from the folks over on the @microsoft/fast
project, this looks like it's an issue in plasmo or parcel.
With v3 of MGT we moved to use the @fluentui/web-component library which is built on top of @microsoft/fast-foundation
, so ultimately when we're using a button, we're importing this https://github.com/microsoft/fast/blob/archives/fast-element-1/packages/web-components/fast-foundation/src/button/index.ts
As you can see there are two direct imports, one for the template and one for the logic.
If you open up the bundled popup.*.js
file in an editor you can trace the dependency loading. Searching for the button.template.js
import I find this:
var _buttonTemplateJs = require("./button.template.js");
parcelHelpers.exportAll(_buttonTemplateJs, exports);
var _buttonJs = require("./button.js");
parcelHelpers.exportAll(_buttonJs, exports);
},{"./button.template.js":false,"./button.js":"xTHA3","@parcel/transformer-js/src/esmodule-helpers.js":"boKlo"}],"xTHA3":[function(require,module,exports) {
So, to me this looks like the button template is being incorrectly tree shaken out.
I think the main issue is that parcel follows ESM standard a bit too closely vs other framework that might be more forgiving with how they resolve ESM (i.e, webpack can be configured to mangle ESM from CJS package.json).
When looking at the package.json of https://www.npmjs.com/package/@fluentui/web-components?activeTab=code , the issue I'm seeing is that it doesn't have the module field or have an export field for module resolution, thus indicating that it is a bundled CJS module.
To be proper ESM, package.json should include export statement + module type, otherwise, parcel would ignore the ESM aspect of it and only grab the top-level file iirc..
I narrowed even more the issue with a combination of parcel bundler + fast components : https://github.com/microsoft/fast/issues/6782
No react, no typescript, no fluent ui at all
Regarding the previous discoveries, I found a workaround to make the MGT v3 happy with plasmo.
Basically, I created a popup/index.html
, sibling to popup/index.tsx
file.
I added explicitely @fluentui/web-components
as a dependency, and, inside this html file:
<!DOCTYPE html>
<html>
<head>
<title>__plasmo_static_index_title__</title>
<meta charset="utf-8" />
</head>
<body>
<script type="module" src="@fluentui/web-components/dist/web-components.js"></script>
</body>
</html>
This way, at runtime, it will use the statically linked library as is, instead of trying to bundle it. The fluentui will be able to find its required files.
This is not a proper solution, because it will break the tree shaking feature and import the whole library, but becasue the extension is loaded from local file system, it will be part of the extension setup.
@stevebeauge I'm going to close this issue now as https://github.com/microsoft/fast/issues/6782 will address the root cause and you have a viable workaround in the mean time.
Describe the bug I'm building a MS edge extension that require login.
I use the
@microsoft/mgt-react
package and especially theLogin
component to show aSign in
button.The extension, built with the V2 of the MGT toolkit is working as expected :
When I migrate to the V3, the MGT stopped to work:
To Reproduce
I create a minimal repro: https://github.com/stevebeauge/repro-mgt-plasmo
From Microsoft Edge:
edge://extensions/
Developer mode
Uncompressed extension
c:\path\to\repro-mgt-plasmo\build\chrome-mv3-dev
folder@microsoft/mgt-react@2.11.2
in the package.json filepnpm install
thenpnpm run dev
Sign in
button is visible βExpected behavior Migrating to V3 should work
Additional information
In order to help diagnose the issue, you can open the page:
extension://<<<ID of the extension>>>/popup.html
. The ID is dependent on the path. It can been view in theextensions
page of edge. In my case:Which results in
extension://mknmhhfclkaeokpkbihchgghfclaobdl/popup.html
.From this page, dev tools are available and we can see there's something in the DOM:
However, there's failures in the error stream:
Full error stack:
When V2 is used, same devtools show:
Environment (please complete the following information):