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

fix(compiler): add delegatesFocus to custom elements targets #3117

Merged
merged 1 commit into from
Oct 25, 2021

Conversation

rwaskiewicz
Copy link
Member

@rwaskiewicz rwaskiewicz commented Oct 21, 2021

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally and any changes were pushed
  • Unit tests (npm test) were run locally and passed
  • E2E Tests (npm run test.karma.prod) were run locally and passed
  • Prettier (npm run prettier) was run locally and passed

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

delegatesFocus is not honored/applied in the dist-custom-elements nor in the dist-custom-elements-bundle output targets (it is simply ignored)

GitHub Issue Number: #3002

What is the new behavior?

this commit allows delegatesFocus to be properly applied to components
generated using the following output targets:

  • dist-custom-elements
  • dist-custom-elements-bundle

the generation of the attachShadow call is moved from a standalone
function to being attached to the prototype of the custom element when
we proxy it. the reason for this is that we need the component metadata
to to determine whether or not each individual component should have
delegateFocus enabled or not.

this change also led to the transition from using ts.create*() calls to
ts.factory.create*() calls for nativeAttachShadowStatement, which is the
general direction I'd like to take such calls, since the former is now
deprecated

Does this introduce a breaking change?

  • Yes
  • No

this led to the removal of the original standalone attachShadow
function. I do not consider this to be a breaking change, as we don't
publicly state our runtime APIs are available for general consumption.

Testing

I've added unit tests and karma tests for this change. The unit tests validate that we output a custom element component correctly (it calls attachShadow in the constructor), while the karma tests ensure that we set the delegatesFocus field properly whenever we use the shadow DOM.

I manually tested this by building and packing this branch (npm ci && npm run build && npm pack) and installed it in https://github.com/Amiiiirali/delegates-focus-test (the repro for the linked GH Issue). Running npm ci && npm run build && npm start in Chrome, Edge, FF (Beta, see other information section below) and Safari confirms the fix

Other information

delegatesFocus is implemented in FireFox 94. At the time of this writing, v94 is only available on the FireFox beta channel. Testing in FF requires a beta build in order to verify this all works.

Docs update: ionic-team/stencil-site#781

@rwaskiewicz rwaskiewicz marked this pull request as ready for review October 21, 2021 20:04
@rwaskiewicz rwaskiewicz requested a review from a team October 21, 2021 20:04
import { transpileModule } from './transpile';
import { nativeComponentTransform } from '../component-native/tranform-to-native-component';

describe('nativeComponentTransform', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't love how this is implemented, but I mirrored the how lazy components are tested here for simplicity's sake

@@ -19,7 +19,7 @@
"karma.prod": "npm run build.sibling && npm run build.invisible-prehydration && npm run build.app && npm run karma.webpack && npm run build.prerender && npm run karma",
"karma.ie": "karma start karma.config.js --browsers=IE --single-run=false",
"karma.edge": "karma start karma.config.js --browsers=Edge --single-run=false",
"karma.webpack": "webpack-cli --config test-app/esm-webpack/webpack.config.js && webpack-cli --config test-app/custom-elements-output-webpack/webpack.config.js && webpack-cli --config test-app/custom-elements-output-tag-class-different/webpack.config.js",
"karma.webpack": "webpack-cli --config test-app/esm-webpack/webpack.config.js && webpack-cli --config test-app/custom-elements-output-webpack/webpack.config.js && webpack-cli --config test-app/custom-elements-output-tag-class-different/webpack.config.js && webpack-cli --config test-app/custom-elements-delegates-focus/webpack.config.js",
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to be working on making this more maintainable this sprint with STENCIL-48. The long term plan is not to tack on to this command for every custom-elements test

this commit allows `delegatesFocus` to be properly applied to components
generated using the following output targets:
- dist-custom-elements
- dist-custom-elements-bundle

the generation of the `attachShadow` call is moved from a standalone
function to being attached to the prototype of the custom element when
we proxy it. the reason for this is that we need the component metadata
to to determine whether or not each individual component should have
delegateFocus enabled or not.

this led to the removal of the original standalone attachShadow
function. I do not consider this to be a breaking change, as we don't
publicly state our runtime APIs are available for general consumption.

this change also led to the transition from using ts.create*() calls to
ts.factory.create*() calls for nativeAttachShadowStatement, which is the
general direction I'd like to take such calls, since the former is now
deprecated

STENCIL-90: "dist-custom-elements-bundle" does not set delegatesFocus
when attaching shadow
const elm: Element = app.querySelector('custom-elements-delegates-focus');

expect(elm.shadowRoot).toBeDefined();
// as of TypeScript 4.3, `delegatesFocus` does not exist on the `shadowRoot` object
Copy link
Member Author

Choose a reason for hiding this comment

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

This may not be true, I need to circle back to this in the AM. Seeing this on a personal project:

// lib.dom.d.ts
interface ShadowRootInit {
    delegatesFocus?: boolean;
    mode: ShadowRootMode;
}

Copy link
Contributor

@splitinfinities splitinfinities left a comment

Choose a reason for hiding this comment

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

Tested this out in the beta FF and Chrome on my library, LGTM!

@rwaskiewicz rwaskiewicz merged commit 2ffb503 into main Oct 25, 2021
@rwaskiewicz rwaskiewicz deleted the stencil90-delegate-focus branch October 25, 2021 17:23
@rwaskiewicz rwaskiewicz changed the title fix(compiler): add deletegatesFocus to custom elements targets fix(compiler): add delegatesFocus to custom elements targets Nov 2, 2021
rwaskiewicz added a commit that referenced this pull request Jun 29, 2023
this commit fixes a bug where projects using the `dist-custom-elements`
output target with `externalRuntime: false` would receive the following
error when building their project:
```
[ WARN  ]  Bundling Warning SOURCEMAP_ERROR
           Error when using sourcemap for reporting an error: Can't resolve original location of error.
```

the cause of this error was attempting to import a function,
`attachShadow` that is no longer exported from the runtime bundle (as of
#3117). to date, this has not
had an effect on stencil (as the import gets treeshaken away). however,
when trying to generate sourcemaps for a project using this
configuration would cause a mismatch between what was expected to be in
the produced output (the import statement) and what was really there (no
import statement)
rwaskiewicz added a commit that referenced this pull request Jul 13, 2023
this commit fixes a bug where projects using the `dist-custom-elements`
output target with `externalRuntime: false` would receive the following
error when building their project:
```
[ WARN  ]  Bundling Warning SOURCEMAP_ERROR
           Error when using sourcemap for reporting an error: Can't resolve original location of error.
```

the cause of this error was attempting to import a function,
`attachShadow` that is no longer exported from the runtime bundle (as of
#3117). to date, this has not
had an effect on stencil (as the import gets treeshaken away). however,
when trying to generate sourcemaps for a project using this
configuration would cause a mismatch between what was expected to be in
the produced output (the import statement) and what was really there (no
import statement)
rwaskiewicz added a commit that referenced this pull request Jul 13, 2023
this commit fixes a bug where projects using the `dist-custom-elements`
output target with `externalRuntime: false` would receive the following
error when building their project:
```
[ WARN  ]  Bundling Warning SOURCEMAP_ERROR
           Error when using sourcemap for reporting an error: Can't resolve original location of error.
```

the cause of this error was attempting to import a function,
`attachShadow` that is no longer exported from the runtime bundle (as of
#3117). to date, this has not
had an effect on stencil (as the import gets treeshaken away). however,
when trying to generate sourcemaps for a project using this
configuration would cause a mismatch between what was expected to be in
the produced output (the import statement) and what was really there (no
import statement)
github-merge-queue bot pushed a commit that referenced this pull request Jul 13, 2023
* fix(compiler): sourcemap generation for non-external runtime

this commit fixes a bug where projects using the `dist-custom-elements`
output target with `externalRuntime: false` would receive the following
error when building their project:
```
[ WARN  ]  Bundling Warning SOURCEMAP_ERROR
           Error when using sourcemap for reporting an error: Can't resolve original location of error.
```

the cause of this error was attempting to import a function,
`attachShadow` that is no longer exported from the runtime bundle (as of
#3117). to date, this has not
had an effect on stencil (as the import gets treeshaken away). however,
when trying to generate sourcemaps for a project using this
configuration would cause a mismatch between what was expected to be in
the produced output (the import statement) and what was really there (no
import statement)

* refactor(compiler): remove unused ATTACH_SHADOW API

this commit removes the RUNTIME_APIS.ATTACH_SHADOW field that is no
longer used in the codebase. it's only usage was in tests for adding
runtime apis, and has been replaced with another field from
`RUNTIME_APIS`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants