-
Notifications
You must be signed in to change notification settings - Fork 795
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
Conversation
import { transpileModule } from './transpile'; | ||
import { nativeComponentTransform } from '../component-native/tranform-to-native-component'; | ||
|
||
describe('nativeComponentTransform', () => { |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
83129fd
to
d035edb
Compare
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 |
There was a problem hiding this comment.
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;
}
There was a problem hiding this 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!
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)
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)
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)
* 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`
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build
) was run locally and any changes were pushednpm test
) were run locally and passednpm run test.karma.prod
) were run locally and passednpm run prettier
) was run locally and passedPull request type
Please check the type of change your PR introduces:
What is the current behavior?
delegatesFocus
is not honored/applied in thedist-custom-elements
nor in thedist-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 componentsgenerated using the following output targets:
the generation of the
attachShadow
call is moved from a standalonefunction 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?
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 thedelegatesFocus
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). Runningnpm ci && npm run build && npm start
in Chrome, Edge, FF (Beta, see other information section below) and Safari confirms the fixOther 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