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

bug: dist-custom-elements with customElementsExportBehavior: "single-export-module" does not execute globalScript #5680

Open
3 tasks done
0m4r opened this issue Apr 18, 2024 · 4 comments
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil

Comments

@0m4r
Copy link

0m4r commented Apr 18, 2024

Prerequisites

Stencil Version

4.16.0

Current Behavior

When configuring stencil using the following configuration, the code in the file set to globalScript is not executed.
The outputTargets dist-custom-elements has set includeGlobalScripts: true

import { reactOutputTarget } from '@stencil/react-output-target';

import { Config } from '@stencil/core';

export const config: Config = {
  namespace: 'stencil-library',
  sourceMap: true,
  globalScript: "./src/global.js",
  extras: {
    enableImportInjection: true,
  },
  outputTargets: [
    {
      type: "dist-custom-elements",
      generateTypeDeclarations: true,
      includeGlobalScripts: true,
      customElementsExportBehavior: "single-export-module",
      minify: false,
    },
    reactOutputTarget({
      componentCorePackage: "stencil-library/dist/",
      proxiesFile: "../react-library/lib/components/stencil-generated/index.ts",
      includeImportCustomElements: true,
      includeDefineCustomElements: undefined,
    }),
  ],
  testing: {
    browserHeadless: "new",
  },
};

Expected Behavior

when globalScript is properly set the outputTargets dist-custom-elements has set includeGlobalScripts: true the code specified in globalScript is executed (as documented here: The outputTargets dist-custom-elements has set includeGlobalScripts: true )

System Info

System: node 20.9.0
    Platform: darwin (23.3.0)
   CPU Model: Apple M2 Pro (12 cpus)
    Compiler: [REDACTED]/stencil-single-export-module/node_modules/@stencil/core/compiler/stencil.js
       Build: 1713191202
     Stencil: 4.16.0 🚛
  TypeScript: 5.4.5
      Rollup: 2.56.3
      Parse5: 7.1.2
      jQuery: 4.0.0-pre
      Terser: 5.30.3

Steps to Reproduce

The issue can be replicated with the code at this git repo: https://github.com/0m4r/stencil-single-export-module-global-script-bug

Once cloned:

Code Reproduction URL

https://github.com/0m4r/stencil-single-export-module-global-script-bug

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label Apr 18, 2024
@christian-bromann christian-bromann self-assigned this Apr 19, 2024
@christian-bromann
Copy link
Member

@0m4r thanks for raising the issue.

This is indeed a weird behavior which I believe has to be fixed in the stencil-ds-output-targets project. As far as I can see, Stencil correctly creates a main entry bundle in packages/stencil-library/dist/components/index.js that, when imported, would execute the global script for the components. From what I see the issue is within the React output target that imports the components directly and therefore ignores the global script from the main entry file.

I will ingest this into our backlog for the team to take a look at.

@christian-bromann christian-bromann removed their assignment Apr 19, 2024
@christian-bromann christian-bromann added Bug: Validated This PR or Issue is verified to be a bug within Stencil and removed triage labels Apr 19, 2024
@0m4r
Copy link
Author

0m4r commented Apr 22, 2024

is it possible to track the progress of the injected ticket? would you be able to share a timeline for it to be worked on and possibly resolved and released? It has quite an impact for the project I am working on and the more information I can collect the better.

Of course, I am also available for any other kind of help I can provide.

@christian-bromann
Copy link
Member

Of course, I am also available for any other kind of help I can provide.

I can't give you any ETAs on when this will be resolved and released. If you like to take a stab at this we are happy to review changes and schedule them into our next release.

@0m4r
Copy link
Author

0m4r commented Apr 22, 2024

I would love to, but I am afraid I do not have enough knowledge to contribute.
I will see what I can do :) thanks for your reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil
Projects
None yet
Development

No branches or pull requests

2 participants