1- import { redirect } from "next/navigation" ;
21import { Suspense } from "react" ;
32import { ViewType } from "react-diff-view" ;
43import { DEFAULT_DIFF_FILES_GLOB } from "^/lib/default-diff-files" ;
5- import destination from "^/lib/destination" ;
64import { parseQuery , QueryParams } from "^/lib/query" ;
75import { createSimplePackageSpec } from "^/lib/SimplePackageSpec" ;
8- import decodeParts from "^/lib/utils/decodeParts" ;
9- import specsToDiff from "^/lib/utils/specsToDiff" ;
10- import splitParts from "^/lib/utils/splitParts" ;
116import BundlephobiaDiff , {
127 BundlephobiaDiffSkeleton ,
138} from "./_page/BundlephobiaDiff" ;
@@ -20,16 +15,18 @@ import PackagephobiaDiff, {
2015import { DIFF_TYPE_PARAM_NAME } from "./_page/paramNames" ;
2116
2217export interface DiffPageProps {
23- params : { a : string ; b : string } ;
24- searchParams : QueryParams & { [ DIFF_TYPE_PARAM_NAME ] : ViewType } ;
18+ params : {
19+ a : string ;
20+ b : string ;
21+ } ;
22+ searchParams : QueryParams & {
23+ [ DIFF_TYPE_PARAM_NAME ] : ViewType ;
24+ } ;
2525}
2626
2727export function generateMetadata ( { params : { a : _a , b : _b } } : DiffPageProps ) {
28- _a = decodeURIComponent ( _a ) ;
29- _b = decodeURIComponent ( _b ) ;
30-
31- const a = createSimplePackageSpec ( _a ) ;
32- const b = createSimplePackageSpec ( _b ) ;
28+ const a = createSimplePackageSpec ( decodeURIComponent ( _a ) ) ;
29+ const b = createSimplePackageSpec ( decodeURIComponent ( _b ) ) ;
3330
3431 return {
3532 title : `Comparing ${ a . name } @${ a . version } ...${ b . name } @${ b . version } ` ,
@@ -50,72 +47,43 @@ const DiffPage = async ({
5047} : DiffPageProps ) : Promise < JSX . Element > => {
5148 const { diffFiles, ...optionsQuery } = searchParams ;
5249
53- const specsOrVersions : [ string , string ] = [
54- decodeURIComponent ( _a ) ,
55- decodeURIComponent ( _b ) ,
56- ] ;
57- const { redirect : redirectTarget , canonicalSpecs } = await destination (
58- specsOrVersions ,
59- ) ;
60-
61- if ( redirectTarget !== false ) {
62- const specsStr = specsToDiff ( canonicalSpecs ) ;
63- const searchStr = Object . entries ( searchParams )
64- . map ( ( [ key , value ] ) => `${ key } =${ value } ` )
65- . join ( "&" ) ;
50+ const options = parseQuery ( {
51+ // If no diffFiles is passed, use the default.
52+ // This is done here, since we don't want a fall back in the API
53+ diffFiles : diffFiles ?? DEFAULT_DIFF_FILES_GLOB ,
54+ ...optionsQuery ,
55+ } ) ;
6656
67- redirect (
68- `/${ specsStr } ` + ( searchStr ?. length > 0 ? `?${ searchStr } ` : "" ) ,
69- ) ;
70- } else {
71- const options = parseQuery ( {
72- // If no diffFiles is passed, use the default.
73- // This is done here, since we don't want a fall back in the API
74- diffFiles : diffFiles ?? DEFAULT_DIFF_FILES_GLOB ,
75- ...optionsQuery ,
76- } ) ;
57+ _a = decodeURIComponent ( _a ) ;
58+ _b = decodeURIComponent ( _b ) ;
7759
78- const [ a , b ] = canonicalSpecs . map ( ( spec ) =>
79- createSimplePackageSpec ( spec ) ,
80- ) ;
60+ const specs = [ _a , _b ] as [ string , string ] ;
61+ const a = createSimplePackageSpec ( _a ) ;
62+ const b = createSimplePackageSpec ( _b ) ;
8163
82- return (
83- < >
84- < DiffIntro
85- alignSelf = "stretch"
86- a = { a }
87- b = { b }
88- services = {
89- < >
90- < Suspense fallback = { < BundlephobiaDiffSkeleton /> } >
91- < BundlephobiaDiff
92- a = { a }
93- b = { b }
94- specs = { canonicalSpecs }
95- />
96- </ Suspense >
97- < Suspense fallback = { < PackagephobiaDiffSkeleton /> } >
98- < PackagephobiaDiff
99- a = { a }
100- b = { b }
101- specs = { canonicalSpecs }
102- />
103- </ Suspense >
104- </ >
105- }
106- options = { options }
107- />
108- < Suspense fallback = { < NpmDiffSkeleton flex = "1" /> } >
109- < NpmDiff
110- a = { a }
111- b = { b }
112- specs = { canonicalSpecs }
113- options = { options }
114- />
115- </ Suspense >
116- </ >
117- ) ;
118- }
64+ return (
65+ < >
66+ < DiffIntro
67+ alignSelf = "stretch"
68+ a = { a }
69+ b = { b }
70+ services = {
71+ < >
72+ < Suspense fallback = { < BundlephobiaDiffSkeleton /> } >
73+ < BundlephobiaDiff a = { a } b = { b } specs = { specs } />
74+ </ Suspense >
75+ < Suspense fallback = { < PackagephobiaDiffSkeleton /> } >
76+ < PackagephobiaDiff a = { a } b = { b } specs = { specs } />
77+ </ Suspense >
78+ </ >
79+ }
80+ options = { options }
81+ />
82+ < Suspense fallback = { < NpmDiffSkeleton flex = "1" /> } >
83+ < NpmDiff a = { a } b = { b } specs = { specs } options = { options } />
84+ </ Suspense >
85+ </ >
86+ ) ;
11987} ;
12088
12189export default DiffPage ;
0 commit comments