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

feat: move to react from preact #2173

Merged
merged 44 commits into from Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0f6ad5d
feat: remove preact (#2169)
capJavert Sep 12, 2023
d9ea655
Merge branch 'main' into WT-1778-move-to-react
capJavert Sep 12, 2023
c49125b
feat: replace preact testing-library with react equivalent (#2175)
capJavert Sep 13, 2023
f7af5b6
Merge branch 'main' into WT-1778-move-to-react
capJavert Sep 13, 2023
c0a5538
Merge branch 'main' into WT-1778-move-to-react
capJavert Sep 13, 2023
5c3a24e
fix: invalid hook call that was crashing extension
capJavert Sep 14, 2023
528d6e5
Merge branch 'main' into WT-1778-move-to-react
capJavert Sep 15, 2023
711aab4
fix: react fragment warnings from dynamicParent component
capJavert Sep 15, 2023
9f5d2f9
fix: dynamicParent placeholder, make children optional
capJavert Sep 15, 2023
ad71527
Merge branch 'main' into WT-1778-move-to-react
capJavert Sep 19, 2023
73fc1a1
chore: remove prefresh
capJavert Sep 19, 2023
09bd629
fix: move to conditional wrapper (#2187)
rebelchris Sep 19, 2023
a4c56f0
fix: make ref optional and default removal (#2188)
rebelchris Sep 19, 2023
ccb9fec
fix: add key to heatmap render (#2190)
rebelchris Sep 19, 2023
422a9c1
fix: always pass a string to `className` prop (#2193)
DragosIorgulescu Sep 19, 2023
ab76f2a
enableSourceHeader` to `FeedItemContainer` via `ArticlePostCard` (#2191)
DragosIorgulescu Sep 19, 2023
cabebbb
fix: hooks conditional usage on `Feed.tsx` (#2192)
DragosIorgulescu Sep 19, 2023
c9f1e5c
fix: prevent default on hide click (#2194)
rebelchris Sep 19, 2023
3719c29
fix: replace onChange with onBlur to set squad handle when focusing o…
omBratteng Sep 19, 2023
19f7ed6
fix: forward ref (#2197)
rebelchris Sep 19, 2023
ecea964
feat: clear interval when hook unmounts (#2198)
capJavert Sep 19, 2023
2db151b
fix: forward ref
rebelchris Sep 19, 2023
8b9d293
fix: don't pass unused props down to `WelcomePostCard` (#2199)
DragosIorgulescu Sep 19, 2023
ad62105
fix: invalid DOM nesting of `AccountDangerZone` (#2201)
omBratteng Sep 19, 2023
0ccc70e
fix: use the correct query key to update reading history cache (#2195)
DragosIorgulescu Sep 19, 2023
37f342a
fix: don't nest button inside button (#2202)
DragosIorgulescu Sep 19, 2023
e48a1b7
fix: make url input always controlled on share post bar (#2200)
DragosIorgulescu Sep 19, 2023
a528efa
fix: add history item timestamp to list key (#2204)
capJavert Sep 19, 2023
d431bc2
fix: passing non dom props to elements (#2203)
sshanzel Sep 19, 2023
f68cde4
Merge branch 'main' into WT-1778-move-to-react
rebelchris Sep 19, 2023
6c51657
feat: add react-query devtools (#2208)
capJavert Sep 19, 2023
8ba0b72
fix: anchor tag inside anchor tag on squad shared post (#2205)
omBratteng Sep 20, 2023
45883ee
fix overlapping promises causing `act()` errors (#2209)
DragosIorgulescu Sep 20, 2023
f2e2ac9
fix: build by checking whether portals would work (#2212)
sshanzel Sep 20, 2023
dd3bb4e
refactor: nested anchor tags (#2215)
sshanzel Sep 20, 2023
8be15a5
fix: test timeouts on alert assertions in the feed (#2213)
DragosIorgulescu Sep 20, 2023
d4242af
fix: lint
sshanzel Sep 20, 2023
7e9f189
fix: notification card z-index (#2216)
sshanzel Sep 20, 2023
7498cdc
Merge branch 'main' into WT-1778-move-to-react
capJavert Sep 20, 2023
21d4d37
Merge branch 'WT-1778-move-to-react' of github.com:dailydotdev/apps i…
capJavert Sep 20, 2023
a639e3f
Merge branch 'main' into WT-1778-move-to-react
capJavert Sep 21, 2023
d2ecb71
Merge branch 'main' into WT-1778-move-to-react
capJavert Sep 28, 2023
0eb7e25
Merge branch 'main' into WT-1778-move-to-react
capJavert Sep 28, 2023
68bfb3c
Merge branch 'main' into WT-1778-move-to-react
capJavert Sep 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions .pnpmfile.cjs
Expand Up @@ -4,14 +4,8 @@ function switchDependency(pkg, dep, newDep) {
}
}

function switchToPreact(pkg, dep) {
switchDependency(pkg, dep, 'npm:@preact/compat@17.0.2');
}

function readPackage(pkg) {
if (pkg.dependencies) {
switchToPreact(pkg, 'react');
switchToPreact(pkg, 'react-dom');
switchDependency(pkg, '@growthbook/growthbook', 'https://gitpkg.now.sh/dailydotdev/growthbook/packages/sdk-js?a0d1a3add257acdbf5353dfd690547feebbada92');
}
return pkg
Expand Down
20 changes: 0 additions & 20 deletions packages/extension/babel.config.js
@@ -1,6 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const sharedPackage = require('../shared/package.json');

module.exports = {
presets: [
Expand Down Expand Up @@ -30,24 +28,6 @@ module.exports = {
regenerator: true,
},
],
[
require.resolve('babel-plugin-module-resolver'),
{
root: ['.'],
alias: {
// Required to remove duplicate dependencies from the build
...Object.keys(sharedPackage.peerDependencies).reduce((acc, dep) => {
if (['react', 'react-dom'].find((name) => name === dep)) {
return {
...acc,
[dep]: path.resolve('./node_modules/preact/compat'),
};
}
return { ...acc, [dep]: path.resolve(`./node_modules/${dep}`) };
}, {}),
},
},
],
],
env: {
production: {
Expand Down
9 changes: 3 additions & 6 deletions packages/extension/package.json
Expand Up @@ -31,10 +31,8 @@
"graphql-request": "^3.6.1",
"idb-keyval": "^5.1.5",
"next": "^12.2.2",
"preact": "^10.8.2",
"preact-render-to-string": "^5.2.0",
"react": "npm:@preact/compat@17.0.2",
"react-dom": "npm:@preact/compat@17.0.2",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-intersection-observer": "^8.34.0",
"react-modal": "^3.15.1",
"react-query": "3.39.1",
Expand All @@ -56,7 +54,7 @@
"@svgr/cli": "^5.5.0",
"@svgr/webpack": "^5.5.0",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/preact": "^2.0.1",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^13.5.0",
"@types/classnames": "^2.2.11",
"@types/dompurify": "^2.3.1",
Expand All @@ -75,7 +73,6 @@
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.5",
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-module-resolver": "^4.1.0",
"babel-plugin-react-remove-properties": "^0.3.0",
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^6.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/companion/Companion.spec.tsx
Expand Up @@ -5,7 +5,7 @@ import {
render,
RenderResult,
screen,
} from '@testing-library/preact';
} from '@testing-library/react';
import defaultUser from '@dailydotdev/shared/__tests__/fixture/loggedUser';
import { UserPostVote } from '@dailydotdev/shared/src/graphql/posts';
import App from './App';
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/companion/Companion.tsx
Expand Up @@ -56,7 +56,7 @@ const Container = ({
return (
<div
ref={containerRef}
data-testId="companion"
data-testid="companion"
className={classNames(
'flex fixed flex-row top-[7.5rem] items-stretch right-0 z-10 max-w-[26.5rem]',
shouldLoad && 'transition-transform',
Expand Down
@@ -1,13 +1,14 @@
import React from 'react';
import { QueryClient, QueryClientProvider } from 'react-query';
import '@testing-library/jest-dom';
import { render, RenderResult, screen } from '@testing-library/preact';
import { render, RenderResult, screen } from '@testing-library/react';
import { companionExplainerVideo } from '@dailydotdev/shared/src/lib/constants';
import { EXTENSION_PERMISSION_KEY } from '@dailydotdev/shared/src/hooks';
import { CompanionPermission } from './CompanionPermission';
import {
registerBrowserContentScripts,
requestContentScripts,
getContentScriptPermission,
} from '../lib/extensionScripts';

let client: QueryClient;
Expand Down Expand Up @@ -51,6 +52,7 @@ beforeEach(() => {
client.setQueryData(EXTENSION_PERMISSION_KEY, () => ({
requestContentScripts,
registerBrowserContentScripts,
getContentScriptPermission,
}));
});

Expand Down
10 changes: 6 additions & 4 deletions packages/extension/src/companion/CompanionPermission.tsx
Expand Up @@ -15,9 +15,7 @@ const CompanionPermissionComponent = (
_,
ref: Ref<HTMLDivElement>,
): ReactElement => {
const { requestContentScripts } = useExtensionPermission({
origin: 'companion permission popup',
});
const { requestContentScripts } = useExtensionPermission();
const link = 'Overview Video';
const button = 'Activate companion';
const title = 'Try the new companion feature!';
Expand All @@ -38,7 +36,11 @@ const CompanionPermissionComponent = (
</p>
<Button
className="mt-1 w-[12.5rem] btn btn-primary"
onClick={() => requestContentScripts()}
onClick={() =>
requestContentScripts({
origin: 'companion permission popup',
})
}
buttonSize={ButtonSize.Small}
>
{button}
Expand Down
6 changes: 1 addition & 5 deletions packages/extension/src/companion/CompanionPopupButton.tsx
Expand Up @@ -5,15 +5,11 @@ import SimpleTooltip from '@dailydotdev/shared/src/components/tooltips/SimpleToo
import CompanionIcon from '@dailydotdev/shared/src/components/icons/App';
import AnalyticsContext from '@dailydotdev/shared/src/contexts/AnalyticsContext';
import { ExperimentWinner } from '@dailydotdev/shared/src/lib/featureValues';
import { useExtensionPermission } from '@dailydotdev/shared/src/hooks';
import { useContentScriptStatus } from '@dailydotdev/shared/src/hooks';
import { CompanionPermission } from './CompanionPermission';

export const CompanionPopupButton = (): ReactElement => {
const { trackEvent } = useContext(AnalyticsContext);
const { useContentScriptStatus } = useExtensionPermission({
origin: 'companion permission button',
});

const { contentScriptGranted, isFetched } = useContentScriptStatus();
const [showCompanionPermission, setShowCompanionPermission] = useState(false);

Expand Down
10 changes: 6 additions & 4 deletions packages/extension/src/companion/useCompanionSettings.ts
@@ -1,12 +1,14 @@
import { useContext, useEffect, useRef } from 'react';
import SettingsContext from '@dailydotdev/shared/src/contexts/SettingsContext';
import { useExtensionPermission } from '@dailydotdev/shared/src/hooks';
import {
useContentScriptStatus,
useExtensionPermission,
} from '@dailydotdev/shared/src/hooks';

export const useCompanionSettings = (origin: string): void => {
export const useCompanionSettings = (): void => {
const isOnLoad = useRef(true);
const { optOutCompanion, loadedSettings } = useContext(SettingsContext);
const { registerBrowserContentScripts, useContentScriptStatus } =
useExtensionPermission({ origin });
const { registerBrowserContentScripts } = useExtensionPermission();
const { contentScriptGranted } = useContentScriptStatus();

useEffect(() => {
Expand Down
33 changes: 12 additions & 21 deletions packages/extension/src/lib/extensionScripts.ts
@@ -1,10 +1,11 @@
import 'content-scripts-register-polyfill';
import { browser, ContentScripts } from 'webextension-polyfill-ts';
import { RequestContentScripts } from '@dailydotdev/shared/src/hooks';
import { useQuery } from 'react-query';
import {
CreateRequestContentScripts,
contentScriptKey,
} from '@dailydotdev/shared/src/hooks';
import { companionPermissionGrantedLink } from '@dailydotdev/shared/src/lib/constants';
import { AnalyticsEvent } from '@dailydotdev/shared/src/lib/analytics';
import { disabledRefetch } from '@dailydotdev/shared/src/lib/func';

export const registerBrowserContentScripts =
(): Promise<ContentScripts.RegisteredContentScript> =>
Expand Down Expand Up @@ -33,14 +34,17 @@ export const getContentScriptPermissionAndRegister =
}
};

const contentScriptKey = 'permission_key';

export const requestContentScripts: RequestContentScripts = (
origin,
export const requestContentScripts: CreateRequestContentScripts = (
client,
trackEvent,
) => {
return async ({ skipRedirect }: { skipRedirect?: boolean } = {}) => {
return async ({
origin,
skipRedirect,
}: {
origin: string;
skipRedirect?: boolean;
}) => {
trackEvent({
event_name: AnalyticsEvent.RequestContentScripts,
extra: JSON.stringify({ origin }),
Expand Down Expand Up @@ -71,16 +75,3 @@ export const requestContentScripts: RequestContentScripts = (
return granted;
};
};

export const useContentScriptStatus = (): {
contentScriptGranted: boolean;
isFetched: boolean;
} => {
const { data: contentScriptGranted, isFetched } = useQuery(
contentScriptKey,
getContentScriptPermission,
disabledRefetch,
);

return { contentScriptGranted, isFetched };
};
11 changes: 8 additions & 3 deletions packages/extension/src/newtab/App.tsx
Expand Up @@ -26,6 +26,7 @@ import { useNotificationContext } from '@dailydotdev/shared/src/contexts/Notific
import { useLazyModal } from '@dailydotdev/shared/src/hooks/useLazyModal';
import { usePrompt } from '@dailydotdev/shared/src/hooks/usePrompt';
import { defaultQueryClientConfig } from '@dailydotdev/shared/src/lib/query';
import { ReactQueryDevtools } from 'react-query/devtools';
import CustomRouter from '../lib/CustomRouter';
import { version } from '../../package.json';
import MainFeedPage from './MainFeedPage';
Expand All @@ -34,10 +35,13 @@ import { BootDataProvider } from '../../../shared/src/contexts/BootProvider';
import {
getContentScriptPermissionAndRegister,
requestContentScripts,
useContentScriptStatus,
registerBrowserContentScripts,
getContentScriptPermission,
} from '../lib/extensionScripts';
import { EXTENSION_PERMISSION_KEY } from '../../../shared/src/hooks';
import {
EXTENSION_PERMISSION_KEY,
useContentScriptStatus,
} from '../../../shared/src/hooks';

const DEFAULT_TAB_TITLE = 'New Tab';
const router = new CustomRouter();
Expand Down Expand Up @@ -70,7 +74,7 @@ function InternalApp({
useQuery(EXTENSION_PERMISSION_KEY, () => ({
requestContentScripts,
registerBrowserContentScripts,
useContentScriptStatus,
getContentScriptPermission,
}));

useEffect(() => {
Expand Down Expand Up @@ -139,6 +143,7 @@ export default function App({
</OnboardingContextProvider>
</SubscriptionContextProvider>
</BootDataProvider>
<ReactQueryDevtools />
</QueryClientProvider>
</ProgressiveEnhancementContextProvider>
</RouterContext.Provider>
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/newtab/MainFeedPage.tsx
Expand Up @@ -38,7 +38,7 @@ export default function MainFeedPage({
const [feedName, setFeedName] = useState<string>('default');
const [searchQuery, setSearchQuery] = useState<string>();
const [showDnd, setShowDnd] = useState(false);
useCompanionSettings('main feed page');
useCompanionSettings();
const { isActive: isDndActive } = useContext(DndContext);
const enableSearch = () => {
setIsSearchOn(true);
Expand Down
4 changes: 2 additions & 2 deletions packages/extension/src/newtab/ShortcutLinks.spec.tsx
Expand Up @@ -2,15 +2,15 @@ import React from 'react';
import nock from 'nock';
import { BootDataProvider } from '@dailydotdev/shared/src/contexts/BootProvider';
import {
act,
fireEvent,
render,
RenderResult,
screen,
waitForElementToBeRemoved,
} from '@testing-library/preact';
} from '@testing-library/react';
import { mocked } from 'ts-jest/utils';
import { QueryClient, QueryClientProvider } from 'react-query';
import { act } from 'preact/test-utils';
import { mockGraphQL } from '@dailydotdev/shared/__tests__/helpers/graphql';
import { waitForNock } from '@dailydotdev/shared/__tests__/helpers/utilities';
import {
Expand Down
6 changes: 0 additions & 6 deletions packages/extension/webpack.config.js
Expand Up @@ -80,12 +80,6 @@ module.exports = {
'webextension-polyfill-ts': path.resolve(
path.join(__dirname, 'node_modules', 'webextension-polyfill-ts'),
),
react: path.resolve(
path.join(__dirname, 'node_modules', 'preact', 'compat'),
),
'react-dom': path.resolve(
path.join(__dirname, 'node_modules', 'preact', 'compat'),
),
},
},

Expand Down
5 changes: 1 addition & 4 deletions packages/shared/__tests__/helpers/utilities.ts
@@ -1,4 +1,4 @@
import { waitFor } from '@testing-library/preact';
import { waitFor } from '@testing-library/react';
import nock from 'nock';

export const expectNockDone = (): void => expect(nock.isDone()).toBeTruthy();
Expand All @@ -12,9 +12,6 @@ export function expectToHaveAttribute(
value: string | null | undefined,
): Promise<void> {
return waitFor(() => {
if (value === 'false') {
return expect(el).not.toHaveAttribute(att);
}
return expect(el).toHaveAttribute(att, value);
});
}
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/package.json
Expand Up @@ -40,8 +40,8 @@
"@dailydotdev/prettier-config": "*",
"@dailydotdev/react-contexify": "^5.0.0",
"@testing-library/jest-dom": "^5.15.0",
"@testing-library/preact": "^3.2.3",
"@testing-library/preact-hooks": "^1.1.0",
"@testing-library/react": "^12.1.5",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^13.5.0",
"@types/classnames": "^2.2.11",
"@types/dompurify": "^2.3.1",
Expand Down Expand Up @@ -93,8 +93,8 @@
"postcss-rem-to-responsive-pixel": "^5.1.1",
"postcss-simple-vars": "^6.0.3",
"prettier": "^2.4.1",
"react": "npm:@preact/compat@17.0.2",
"react-dom": "npm:@preact/compat@17.0.2",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-intersection-observer": "^8.32.2",
"react-modal": "^3.14.3",
"react-query": "3.39.1",
Expand Down