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(core): Angular web detection and other minor changes #11491

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/core/src/Platform/detection/Angular.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { processExists, windowExists } from './helpers';
import { documentExists, processExists, windowExists } from './helpers';

// Tested with @angular/core 16.0.0

export function angularWebDetect() {
return windowExists() && typeof window['ng'] !== 'undefined';
const angularVersionSetInDocument = Boolean(
documentExists() && document.querySelector('[ng-version]')
);
const angularContentSetInWindow = Boolean(
// @ts-ignore
windowExists() && typeof window['ng'] !== 'undefined'
);
return angularVersionSetInDocument || angularContentSetInWindow;
}

export function angularSSRDetect() {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/Platform/detection/Expo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import { globalExists } from './helpers';
// Tested with expo 48 / react-native 0.71.3

export function expoDetect() {
// @ts-ignore
return globalExists() && typeof global['expo'] !== 'undefined';
}
1 change: 1 addition & 0 deletions packages/core/src/Platform/detection/Next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { globalExists, keyPrefixMatch, windowExists } from './helpers';
// Tested with next 13.4 / react 18.2

export function nextWebDetect() {
// @ts-ignore
return windowExists() && window['next'] && typeof window['next'] === 'object';
}

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/Platform/detection/Nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import { globalExists, windowExists } from './helpers';
export function nuxtWebDetect() {
return (
windowExists() &&
// @ts-ignore
(window['__NUXT__'] !== undefined || window['$nuxt'] !== undefined)
);
}

export function nuxtSSRDetect() {
// @ts-ignore
return globalExists() && typeof global['__NUXT_PATHS__'] !== 'undefined';
}
8 changes: 4 additions & 4 deletions packages/core/src/Platform/detection/React.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { documentExists, processExists, windowExists } from './helpers';
// Tested with react 18.2 - built using Vite

export function reactWebDetect() {
const elementKeyPrefixedWithReact = k => {
return k.startsWith('_react') || k.startsWith('__react');
const elementKeyPrefixedWithReact = key => {
return key.startsWith('_react') || key.startsWith('__react');
};
const elementIsReactEnabled = e => {
return Object.keys(e).find(elementKeyPrefixedWithReact);
const elementIsReactEnabled = element => {
return Object.keys(element).find(elementKeyPrefixedWithReact);
};
const allElementsWithId = () => Array.from(document.querySelectorAll('[id]'));

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Platform/detection/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export const processExists = () => {
return typeof process !== 'undefined';
};

export const keyPrefixMatch = (object, prefix) => {
export const keyPrefixMatch = (object: object, prefix: string) => {
return !!Object.keys(object).find(key => key.startsWith(prefix));
};