Skip to content

Update dependencies #575

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

Merged
merged 17 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion fluent-gecko/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default [
intro: `/* fluent-react@${reactPkg.version} */`,
},
context: "this",
external: ["react", "prop-types"],
external: ["react"],
plugins: [nodeResolve()],
},
{
Expand Down
52 changes: 27 additions & 25 deletions fluent-react/example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion fluent-react/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"@fluent/langneg": "^0.6.0",
"@fluent/sequence": "^0.7.0",
"cached-iterable": "^0.3.0",
"prop-types": "^15.7.2",
"react": "^16.8.0",
"react-dom": "^16.8.0"
},
Expand Down
5 changes: 2 additions & 3 deletions fluent-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
],
"scripts": {
"build": "tsc -p ./tsconfig.build.json",
"postbuild": "rollup -c ../rollup.config.mjs --globals @fluent/sequence:FluentSequence,cached-iterable:CachedIterable,react:React,prop-types:PropTypes",
"postbuild": "rollup -c ../rollup.config.mjs --globals @fluent/sequence:FluentSequence,cached-iterable:CachedIterable,react:React",
"docs": "typedoc --options ../typedoc.config.cjs --tsconfig ./tsconfig.build.json",
"test": "jest --collect-coverage"
},
Expand All @@ -59,8 +59,7 @@
},
"dependencies": {
"@fluent/sequence": "^0.7.0",
"cached-iterable": "^0.3.0",
"prop-types": "^15.7.2"
"cached-iterable": "^0.3.0"
},
"peerDependencies": {
"@fluent/bundle": ">=0.16.0 <0.18.0",
Expand Down
5 changes: 0 additions & 5 deletions fluent-react/src/localized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
isValidElement,
useContext
} from "react";
import PropTypes from "prop-types";
import voidElementTags from "../vendor/voidElementTags.js";
import { FluentContext } from "./context.js";
import { FluentVariable } from "@fluent/bundle";
Expand Down Expand Up @@ -222,7 +221,3 @@ export function Localized(props: LocalizedProps): ReactElement {
}

export default Localized;

Localized.propTypes = {
children: PropTypes.node
};
12 changes: 2 additions & 10 deletions fluent-react/src/provider.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { createElement, ReactNode, ReactElement } from "react";
import PropTypes from "prop-types";
import { FluentContext } from "./context.js";
import { ReactLocalization } from "./localization.js";

interface LocalizationProviderProps {
children?: ReactNode;
children: ReactNode;
l10n: ReactLocalization;
}

Expand All @@ -29,14 +28,7 @@ export function LocalizationProvider(
): ReactElement {
return createElement(
FluentContext.Provider,
{
value: props.l10n
},
{ value: props.l10n },
props.children
);
}

LocalizationProvider.propTypes = {
Copy link
Member

Choose a reason for hiding this comment

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

Question: Is this a behavior change for our users? Not everyone uses TypeScript, and this could provide valuable runtime checks if users are relying on the added safety here.

Copy link
Member Author

Choose a reason for hiding this comment

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

The prop-types methods are effectively no-ops in production, so I don't think that this should be considered a change in behaviour. It's removed here because issues like facebook/prop-types#354 make it difficult to support react@17 while keeping it as a dependency.

Copy link
Member

Choose a reason for hiding this comment

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

I would somewhat disagree with the change in behavior, as it's still used in development mode. However, I won't block on this change if you feel the dependency management is too complex.

children: PropTypes.element.isRequired,
l10n: PropTypes.instanceOf(ReactLocalization).isRequired,
};
14 changes: 0 additions & 14 deletions fluent-react/test/provider_valid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,4 @@ describe("LocalizationProvider - validation", () => {
);
expect(renderer.toJSON()).toMatchInlineSnapshot(`<div />`);
});

test("without a child", () => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion (blocking): I'm nervous about this change, since we can't do this with TypeScript type checks, but our users might. For instance in Firefox DevTools this is used without type checks.

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 PR drops two tests. They expected these to throw:

<LocalizationProvider l10n={new ReactLocalization([])} />
<LocalizationProvider />

I don't think there's any actual benefit from throwing for these, and doing so is in fact surprising. A LocalizationProvider is a Context.Provider, which normally does not require its children to be non-empty. It just does nothing in that case.

The second checks that the l10n prop is defined. This will continue to throw in actual use, as the users of the context get its value with the TS type ReactLocalization | null, and handle the latter by throwing. This is already effectively checked by tests in fluent-react/test/localized_valid.test.js.

@gregtatum Would you like me to add a more specific test to the Localized test suite covering the missing-prop case?

Copy link
Member

Choose a reason for hiding this comment

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

I think there is some value in exercising these code paths as users of this package could do surprising things with it. Without the throws, I'm less opinionated if the tests stay or if they go.

expect(() => {
TestRenderer.create(
<LocalizationProvider l10n={new ReactLocalization([])} />
);
}).toThrow(/required/);
});

test("without the l10n prop", () => {
expect(() => {
TestRenderer.create(<LocalizationProvider />);
}).toThrow(/marked as required/);
});
});
24 changes: 16 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.