Skip to content

Commit

Permalink
Don't be to restrictive on the type of the Link component passed by d…
Browse files Browse the repository at this point in the history
…sfr start, it provide no added safety #247
  • Loading branch information
garronej committed Apr 3, 2024
1 parent e6103d6 commit cc17baa
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/next-appdir/DsfrHead.tsx
Expand Up @@ -7,7 +7,7 @@ import FaviconIco from "../dsfr/favicon/favicon.ico";
import { getScriptToRunAsap } from "../useIsDark/scriptToRunAsap";
import { fontUrlByFileBasename } from "./zz_internal/fontUrlByFileBasename";
import { getDefaultColorSchemeServerSide } from "./zz_internal/defaultColorScheme";
import { setLink, type RegisterLink } from "../link";
import { setLink } from "../link";
import { assert } from "tsafe/assert";
//NOTE: As of now there is no way to enforce ordering in Next Appdir
//See: https://github.com/vercel/next.js/issues/16630
Expand All @@ -22,7 +22,7 @@ export type DsfrHeadProps = {
*/
preloadFonts?: (keyof typeof fontUrlByFileBasename)[];
/** Default: <a /> */
Link?: RegisterLink extends { Link: infer Link } ? Link : undefined;
Link?: Function;
/**
* When set, the value will be used as the nonce attribute of subsequent script tags.
*
Expand Down Expand Up @@ -68,7 +68,7 @@ export function DsfrHead(props: DsfrHeadProps) {

useMemo(() => {
if (Link !== undefined) {
setLink({ Link });
setLink({ "Link": Link as any });
}
}, [Link]);

Expand Down
5 changes: 2 additions & 3 deletions src/next-appdir/zz_internal/start.ts
@@ -1,5 +1,4 @@
import { start } from "../../start";
import type { RegisterLink } from "../../link";
import { setLink } from "../../link";
import { type DefaultColorScheme, setDefaultColorSchemeClientSide } from "./defaultColorScheme";
import { isBrowser } from "../../tools/isBrowser";
Expand All @@ -14,7 +13,7 @@ export function startReactDsfr(params: {
/** Default: false */
verbose?: boolean;
/** Default: <a /> */
Link?: RegisterLink extends { Link: infer Link } ? Link : undefined;
Link?: Function;
/**
* When true, the nonce of the script tag will be checked, fetched from {@link DsfrHead} component and injected in react-dsfr scripts.
*
Expand Down Expand Up @@ -54,7 +53,7 @@ export function startReactDsfr(params: {
setDefaultColorSchemeClientSide({ defaultColorScheme });

if (Link !== undefined) {
setLink({ Link });
setLink({ "Link": Link as any });
}

if (isBrowser) {
Expand Down
4 changes: 2 additions & 2 deletions src/next-pagesdir.tsx
Expand Up @@ -32,7 +32,7 @@ export type CreateNextDsfrIntegrationApiParams = {
/** Default: false */
verbose?: boolean;
/** Default: <a /> */
Link?: RegisterLink extends { Link: infer Link } ? Link : undefined;
Link?: Function;
/** If not provided no fonts are preloaded.
* Preloading of fonts is only enabled in production.
*/
Expand Down Expand Up @@ -121,7 +121,7 @@ export function createNextDsfrIntegrationApi(
const actions: (() => void)[] = [];

if (Link !== undefined) {
setLink({ Link });
setLink({ "Link": Link as any });
}

if (useLang !== undefined) {
Expand Down
4 changes: 2 additions & 2 deletions src/spa.ts
Expand Up @@ -12,7 +12,7 @@ export function startReactDsfr(params: {
/** Default: false */
verbose?: boolean;
/** Default: <a /> */
Link?: RegisterLink extends { Link: infer Link } ? Link : undefined;
Link?: Function;
/** Default: ()=> "fr" */
useLang?: () => string;
/**
Expand Down Expand Up @@ -50,7 +50,7 @@ export function startReactDsfr(params: {
} = params;

if (Link !== undefined) {
setLink({ Link });
setLink({ "Link": Link as any });
}

if (useLang !== undefined) {
Expand Down

0 comments on commit cc17baa

Please sign in to comment.