Skip to content

Commit

Permalink
chore(compiler): remove safari10 extras flag (#4421)
Browse files Browse the repository at this point in the history
* remove safari10 extras flag

* remove `safari10` references in some tests

* add field removal to breaking changes
  • Loading branch information
tanner-reits committed May 30, 2023
1 parent 3ee20b7 commit 283fd5c
Show file tree
Hide file tree
Showing 17 changed files with 16 additions and 73 deletions.
5 changes: 5 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ the [dynamic `import()`
function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import)
for use at runtime. For Stencil v4.0.0 this field and corresponding behavior has been removed.

##### `__deprecated__safari10`

If `extras.__deprecated__safari10` is set to `true` the Stencil runtime will patch ES module
support for Safari 10. In Stencil v4.0.0 this field and corresponding behavior has been removed.

## Stencil v3.0.0

* [General](#general)
Expand Down
2 changes: 0 additions & 2 deletions src/app-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ export const BUILD: BuildConditionals = {
cloneNodeFix: false,
hydratedAttribute: false,
hydratedClass: true,
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
safari10: false,
scriptDataOpts: false,
scopedSlotTextContentFix: false,
// TODO(STENCIL-662): Remove code related to deprecated shadowDomShim field
Expand Down
42 changes: 9 additions & 33 deletions src/client/client-patch-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,20 @@ export const patchBrowser = (): Promise<d.CustomElementsDefineOptions> => {
}

// @ts-ignore
const scriptElm =
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
BUILD.scriptDataOpts || BUILD.safari10
? Array.from(doc.querySelectorAll('script')).find(
(s) =>
new RegExp(`\/${NAMESPACE}(\\.esm)?\\.js($|\\?|#)`).test(s.src) ||
s.getAttribute('data-stencil-namespace') === NAMESPACE
)
: null;
const scriptElm = BUILD.scriptDataOpts
? Array.from(doc.querySelectorAll('script')).find(
(s) =>
new RegExp(`\/${NAMESPACE}(\\.esm)?\\.js($|\\?|#)`).test(s.src) ||
s.getAttribute('data-stencil-namespace') === NAMESPACE
)
: null;
const importMeta = import.meta.url;
const opts = BUILD.scriptDataOpts ? ((scriptElm as any) || {})['data-opts'] || {} : {};

// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
if (BUILD.safari10 && 'onbeforeload' in scriptElm && !history.scrollRestoration /* IS_ESM_BUILD */) {
// Safari < v11 support: This IF is true if it's Safari below v11.
// This fn cannot use async/await since Safari didn't support it until v11,
// however, Safari 10 did support modules. Safari 10 also didn't support "nomodule",
// so both the ESM file and nomodule file would get downloaded. Only Safari
// has 'onbeforeload' in the script, and "history.scrollRestoration" was added
// to Safari in v11. Return a noop then() so the async/await ESM code doesn't continue.
// IS_ESM_BUILD is replaced at build time so this check doesn't happen in systemjs builds.
return {
then() {
/* promise noop */
},
} as any;
}

// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
if (!BUILD.safari10 && importMeta !== '') {
if (importMeta !== '') {
opts.resourcesUrl = new URL('.', importMeta).href;
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
} else if (BUILD.safari10) {
opts.resourcesUrl = new URL(
'.',
new URL(scriptElm.getAttribute('data-resources-url') || scriptElm.src, win.location.href)
).href;
}

return promiseResolve(opts);
};

Expand Down
2 changes: 0 additions & 2 deletions src/compiler/app-core/app-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ export const updateBuildConditionals = (config: Config, b: BuildConditionals) =>
b.slotChildNodesFix = config.extras.slotChildNodesFix;
b.cloneNodeFix = config.extras.cloneNodeFix;
b.lifecycleDOMEvents = !!(b.isDebug || config._isTesting || config.extras.lifecycleDOMEvents);
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
b.safari10 = config.extras.__deprecated__safari10;
b.scopedSlotTextContentFix = !!config.extras.scopedSlotTextContentFix;
b.scriptDataOpts = config.extras.scriptDataOpts;
// TODO(STENCIL-662): Remove code related to deprecated shadowDomShim field
Expand Down
2 changes: 0 additions & 2 deletions src/compiler/config/test/validate-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,6 @@ describe('validation', () => {
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
expect(config.extras.__deprecated__cssVarsShim).toBe(false);
expect(config.extras.lifecycleDOMEvents).toBe(false);
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
expect(config.extras.__deprecated__safari10).toBe(false);
expect(config.extras.scriptDataOpts).toBe(false);
// TODO(STENCIL-662): Remove code related to deprecated shadowDomShim field
expect(config.extras.__deprecated__shadowDomShim).toBe(false);
Expand Down
2 changes: 0 additions & 2 deletions src/compiler/config/validate-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ export const validateConfig = (
// TODO(STENCIL-659): Remove code implementing the CSS variable shim
validatedConfig.extras.__deprecated__cssVarsShim = !!validatedConfig.extras.__deprecated__cssVarsShim;
validatedConfig.extras.lifecycleDOMEvents = !!validatedConfig.extras.lifecycleDOMEvents;
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
validatedConfig.extras.__deprecated__safari10 = !!validatedConfig.extras.__deprecated__safari10;
validatedConfig.extras.scriptDataOpts = !!validatedConfig.extras.scriptDataOpts;
// TODO(STENCIL-662): Remove code related to deprecated shadowDomShim field
validatedConfig.extras.__deprecated__shadowDomShim = !!validatedConfig.extras.__deprecated__shadowDomShim;
Expand Down
7 changes: 1 addition & 6 deletions src/compiler/optimize/optimize-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ export const optimizeJs = async (inputOpts: OptimizeJsInput) => {

try {
const prettyOutput = !!inputOpts.pretty;
const config: Config = {
extras: {
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
__deprecated__safari10: true,
},
};
const config: Config = {};
const sourceTarget = inputOpts.target === 'es5' ? 'es5' : 'latest';
const minifyOpts = getTerserOptions(config, sourceTarget, prettyOutput);

Expand Down
3 changes: 1 addition & 2 deletions src/compiler/optimize/optimize-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ export const optimizeModule = async (
export const getTerserOptions = (config: Config, sourceTarget: SourceTarget, prettyOutput: boolean): MinifyOptions => {
const opts: MinifyOptions = {
ie8: false,
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
safari10: !!config.extras.__deprecated__safari10,
safari10: false,
format: {},
sourceMap: config.sourceMap,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ const getHydrateBuildConditionals = (config: d.ValidatedConfig, cmps: d.Componen
build.cloneNodeFix = false;
build.appendChildSlotFix = false;
build.slotChildNodesFix = false;
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
build.safari10 = false;
// TODO(STENCIL-662): Remove code related to deprecated shadowDomShim field
build.shadowDomShim = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export const getHydrateBuildConditionals = (cmps: d.ComponentCompilerMeta[]) =>
build.cssAnnotations = true;
// TODO(STENCIL-662): Remove code related to deprecated shadowDomShim field
build.shadowDomShim = true;
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
build.safari10 = false;
build.hydratedAttribute = false;
build.hydratedClass = true;
build.scriptDataOpts = false;
Expand Down
2 changes: 0 additions & 2 deletions src/declarations/stencil-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ export interface BuildConditionals extends Partial<BuildFeatures> {
hydratedAttribute?: boolean;
hydratedClass?: boolean;
initializeNextTick?: boolean;
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
safari10?: boolean;
scriptDataOpts?: boolean;
// TODO(STENCIL-662): Remove code related to deprecated shadowDomShim field
shadowDomShim?: boolean;
Expand Down
11 changes: 0 additions & 11 deletions src/declarations/stencil-public-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,6 @@ export interface ConfigExtras {
*/
lifecycleDOMEvents?: boolean;

// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
/**
* Safari 10 supports ES modules with `<script type="module">`, however, it did not implement
* `<script nomodule>`. When set to `true`, the runtime will patch support for Safari 10
* due to its lack of `nomodule` support.
* Defaults to `false`.
*
* @deprecated Since Stencil v3.0.0, Safari 10 is no longer supported.
*/
__deprecated__safari10?: boolean;

/**
* It is possible to assign data to the actual `<script>` element's `data-opts` property,
* which then gets passed to Stencil's initial bootstrap. This feature is only required
Expand Down
2 changes: 0 additions & 2 deletions src/testing/reset-build-conditionals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ export function resetBuildConditionals(b: d.BuildConditionals) {
b.appendChildSlotFix = false;
b.cloneNodeFix = false;
b.hotModuleReplacement = false;
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
b.safari10 = false;
b.scriptDataOpts = false;
b.scopedSlotTextContentFix = false;
b.slotChildNodesFix = false;
Expand Down
2 changes: 0 additions & 2 deletions src/testing/spec-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ export async function newSpecPage(opts: NewSpecPageOptions): Promise<SpecPage> {
BUILD.cloneNodeFix = false;
// TODO(STENCIL-662): Remove code related to deprecated shadowDomShim field
BUILD.shadowDomShim = false;
// TODO(STENCIL-663): Remove code related to deprecated `safari10` field.
BUILD.safari10 = false;
BUILD.attachStyles = !!opts.attachStyles;

if (typeof opts.url === 'string') {
Expand Down
1 change: 0 additions & 1 deletion test/jest-spec-runner/stencil.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const config: Config = {
hydratedFlag: null,
extras: {
cssVarsShim: false,
safari10: false,
scriptDataOpts: false,
shadowDomShim: false,
},
Expand Down
1 change: 0 additions & 1 deletion test/karma/stencil.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const config: Config = {
cloneNodeFix: true,
cssVarsShim: true,
lifecycleDOMEvents: true,
safari10: true,
scopedSlotTextContentFix: true,
scriptDataOpts: true,
shadowDomShim: true,
Expand Down
1 change: 0 additions & 1 deletion test/todo-app/stencil.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const config: Config = {
hydratedFlag: null,
extras: {
cssVarsShim: false,
safari10: false,
scriptDataOpts: false,
shadowDomShim: false,
},
Expand Down

0 comments on commit 283fd5c

Please sign in to comment.