rari 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/{server-BwDou3Zb.js → server-MkYb94pQ.js} +5 -4
- package/dist/server.js +1 -1
- package/package.json +1 -1
- package/src/vite/index.ts +70 -285
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent, Routes, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, router_default, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-CcEhh-F7.js";
|
|
2
|
-
import { FileRouteGenerator, convertFilePatternToRoutePattern, createReactDOMOptimization, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-
|
|
2
|
+
import { FileRouteGenerator, convertFilePatternToRoutePattern, createReactDOMOptimization, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-MkYb94pQ.js";
|
|
3
3
|
import "./server-build-DaBgiV55.js";
|
|
4
4
|
|
|
5
5
|
export { FileRouteGenerator, HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent as Route, router_default as RouterProvider, Routes, buildSearchString, buildUrl, convertFilePatternToRoutePattern, createHttpRuntimeClient, createReactDOMOptimization, createRouteManifest, defineRariConfig, extractParamNames, findMatchingRoute, generateFileRoutes, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, loadRouteManifest, normalizePathname, parseSearchParams, parseUrl, rari, rariRouter, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, validateRoutes, watchFileRoutes, withRouter };
|
|
@@ -5111,7 +5111,7 @@ var require_chokidar = __commonJS({ "../../node_modules/.pnpm/chokidar@3.6.0/nod
|
|
|
5111
5111
|
|
|
5112
5112
|
//#endregion
|
|
5113
5113
|
//#region src/router/file-routes.ts
|
|
5114
|
-
var import_chokidar$1 = __toESM(require_chokidar());
|
|
5114
|
+
var import_chokidar$1 = __toESM(require_chokidar(), 1);
|
|
5115
5115
|
var FileRouteGenerator = class {
|
|
5116
5116
|
pagesDir;
|
|
5117
5117
|
extensions;
|
|
@@ -5420,7 +5420,7 @@ function convertFilePatternToRoutePattern(pattern) {
|
|
|
5420
5420
|
|
|
5421
5421
|
//#endregion
|
|
5422
5422
|
//#region src/router/vite-plugin.ts
|
|
5423
|
-
var import_chokidar = __toESM(require_chokidar());
|
|
5423
|
+
var import_chokidar = __toESM(require_chokidar(), 1);
|
|
5424
5424
|
const DEFAULT_OPTIONS = {
|
|
5425
5425
|
pagesDir: "src/pages",
|
|
5426
5426
|
extensions: [
|
|
@@ -5964,8 +5964,9 @@ if (import.meta.hot) {
|
|
|
5964
5964
|
config.build.rolldownOptions.treeshake = config.build.rolldownOptions.treeshake || {
|
|
5965
5965
|
moduleSideEffects: (id) => {
|
|
5966
5966
|
if (id.includes(".css") || id.includes("polyfill")) return true;
|
|
5967
|
-
if (id.includes("react-dom") || id.includes("react") || id.includes("scheduler") || id.includes("react-dom/client") || id.includes("react-dom/server")) return
|
|
5968
|
-
return false;
|
|
5967
|
+
if (id.includes("react-dom") || id.includes("react") || id.includes("scheduler") || id.includes("react-dom/client") || id.includes("react-dom/server")) return true;
|
|
5968
|
+
if (id.includes("node_modules") && !id.includes("react")) return false;
|
|
5969
|
+
return true;
|
|
5969
5970
|
},
|
|
5970
5971
|
unknownGlobalSideEffects: false
|
|
5971
5972
|
};
|
package/dist/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent, Routes, buildSearchString, buildUrl, createHttpRuntimeClient, extractParamNames, findMatchingRoute, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, normalizePathname, parseSearchParams, parseUrl, router_default, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, withRouter } from "./runtime-client-CcEhh-F7.js";
|
|
2
|
-
import { FileRouteGenerator, convertFilePatternToRoutePattern, createReactDOMOptimization, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-
|
|
2
|
+
import { FileRouteGenerator, convertFilePatternToRoutePattern, createReactDOMOptimization, createRouteManifest, defineRariConfig, generateFileRoutes, loadRouteManifest, rari, rariRouter, validateRoutes, watchFileRoutes } from "./server-MkYb94pQ.js";
|
|
3
3
|
import "./server-build-DaBgiV55.js";
|
|
4
4
|
|
|
5
5
|
export { FileRouteGenerator, HttpRuntimeClient, Link, Navigate, Outlet, RouteComponent as Route, router_default as RouterProvider, Routes, buildSearchString, buildUrl, convertFilePatternToRoutePattern, createHttpRuntimeClient, createReactDOMOptimization, createRouteManifest, defineRariConfig, extractParamNames, findMatchingRoute, generateFileRoutes, getRoutePriority, isDynamicRoute, isPathActive, joinPaths, loadRouteManifest, normalizePathname, parseSearchParams, parseUrl, rari, rariRouter, useNavigation, useParams, usePathname, useRoute, useRouter, useSearchParams, validateRoutes, watchFileRoutes, withRouter };
|
package/package.json
CHANGED
package/src/vite/index.ts
CHANGED
|
@@ -6,7 +6,6 @@ import fs from 'node:fs'
|
|
|
6
6
|
import path from 'node:path'
|
|
7
7
|
import process from 'node:process'
|
|
8
8
|
import * as acorn from 'acorn'
|
|
9
|
-
import { minify } from 'rollup-plugin-esbuild'
|
|
10
9
|
import { createServerBuildPlugin } from './server-build'
|
|
11
10
|
|
|
12
11
|
interface RariOptions {
|
|
@@ -228,6 +227,7 @@ export function rari(options: RariOptions = {}): Plugin[] {
|
|
|
228
227
|
|
|
229
228
|
newCode += `
|
|
230
229
|
|
|
230
|
+
// HMR acceptance for server components
|
|
231
231
|
if (import.meta.hot) {
|
|
232
232
|
import.meta.hot.accept(() => {
|
|
233
233
|
// Server component updated, no need to reload
|
|
@@ -384,9 +384,6 @@ if (import.meta.hot) {
|
|
|
384
384
|
(config.resolve as any).alias = {
|
|
385
385
|
...existingResolveAlias,
|
|
386
386
|
'react-dom/server': 'react-dom/server.browser',
|
|
387
|
-
'react-dom$': 'react-dom/client',
|
|
388
|
-
'react-dom/cjs/react-dom.production.min.js': 'react-dom/client',
|
|
389
|
-
'react-dom/cjs/react-dom.development.js': 'react-dom/client',
|
|
390
387
|
}
|
|
391
388
|
|
|
392
389
|
const existingAlias: Array<{
|
|
@@ -519,46 +516,6 @@ if (import.meta.hot) {
|
|
|
519
516
|
config.build = config.build || {}
|
|
520
517
|
config.build.rolldownOptions = config.build.rolldownOptions || {}
|
|
521
518
|
|
|
522
|
-
config.build.rolldownOptions.plugins
|
|
523
|
-
= config.build.rolldownOptions.plugins || []
|
|
524
|
-
if (Array.isArray(config.build.rolldownOptions.plugins)) {
|
|
525
|
-
config.build.rolldownOptions.plugins.push(minify())
|
|
526
|
-
|
|
527
|
-
config.build.rolldownOptions.plugins.push({
|
|
528
|
-
name: 'html-css-optimizer',
|
|
529
|
-
generateBundle(options, bundle) {
|
|
530
|
-
Object.keys(bundle).forEach((fileName) => {
|
|
531
|
-
const file = bundle[fileName]
|
|
532
|
-
if (file.type === 'asset' && fileName.endsWith('.html')) {
|
|
533
|
-
let html = file.source as string
|
|
534
|
-
|
|
535
|
-
html = html.replace(
|
|
536
|
-
/<link\s+rel="stylesheet"\s+crossorigin\s+href="([^"]+\.css)"\s*>/g,
|
|
537
|
-
(match, href) => {
|
|
538
|
-
return `<link rel="preload" as="style" crossorigin href="${href}" fetchpriority="high" onload="this.onload=null;this.rel='stylesheet'">
|
|
539
|
-
<noscript><link rel="stylesheet" crossorigin href="${href}"></noscript>`
|
|
540
|
-
},
|
|
541
|
-
)
|
|
542
|
-
|
|
543
|
-
const scriptMatch = html.match(
|
|
544
|
-
/<script\s+type="module"\s+crossorigin\s+src="([^"]+)"\s*><\/script>/,
|
|
545
|
-
)
|
|
546
|
-
if (scriptMatch) {
|
|
547
|
-
const mainJsHref = scriptMatch[1]
|
|
548
|
-
html = html.replace(
|
|
549
|
-
scriptMatch[0],
|
|
550
|
-
`<link rel="preload" as="script" crossorigin href="${mainJsHref}" fetchpriority="high">
|
|
551
|
-
<script type="module" crossorigin src="${mainJsHref}" fetchpriority="high"></script>`,
|
|
552
|
-
)
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
file.source = html
|
|
556
|
-
}
|
|
557
|
-
})
|
|
558
|
-
},
|
|
559
|
-
})
|
|
560
|
-
}
|
|
561
|
-
|
|
562
519
|
if (!config.build.rolldownOptions.input) {
|
|
563
520
|
config.build.rolldownOptions.input = {
|
|
564
521
|
main: './index.html',
|
|
@@ -571,31 +528,22 @@ if (import.meta.hot) {
|
|
|
571
528
|
? config.build.rolldownOptions.output[0] || {}
|
|
572
529
|
: config.build.rolldownOptions.output
|
|
573
530
|
|
|
574
|
-
outputConfig.manualChunks
|
|
575
|
-
|
|
576
|
-
id
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
return 'scheduler'
|
|
591
|
-
}
|
|
592
|
-
if (id.includes('markdown-it') || id.includes('shiki')) {
|
|
593
|
-
return 'vendor'
|
|
594
|
-
}
|
|
595
|
-
if (id.includes('node_modules')) {
|
|
596
|
-
return 'vendor'
|
|
597
|
-
}
|
|
598
|
-
}
|
|
531
|
+
outputConfig.manualChunks
|
|
532
|
+
= outputConfig.manualChunks
|
|
533
|
+
|| ((id) => {
|
|
534
|
+
if (id.includes('react-dom')) {
|
|
535
|
+
return 'react-dom'
|
|
536
|
+
}
|
|
537
|
+
if (id.includes('react') && !id.includes('react-dom')) {
|
|
538
|
+
return 'react'
|
|
539
|
+
}
|
|
540
|
+
if (id.includes('markdown-it') || id.includes('shiki')) {
|
|
541
|
+
return 'vendor'
|
|
542
|
+
}
|
|
543
|
+
if (id.includes('node_modules')) {
|
|
544
|
+
return 'vendor'
|
|
545
|
+
}
|
|
546
|
+
})
|
|
599
547
|
|
|
600
548
|
config.build.rolldownOptions.treeshake = config.build.rolldownOptions
|
|
601
549
|
.treeshake || {
|
|
@@ -603,26 +551,19 @@ if (import.meta.hot) {
|
|
|
603
551
|
if (id.includes('.css') || id.includes('polyfill')) {
|
|
604
552
|
return true
|
|
605
553
|
}
|
|
606
|
-
// Preserve side effects for React modules to prevent import issues
|
|
607
554
|
if (
|
|
608
555
|
id.includes('react-dom')
|
|
609
556
|
|| id.includes('react')
|
|
610
557
|
|| id.includes('scheduler')
|
|
611
|
-
|| id.includes('react-dom/client')
|
|
612
|
-
|| id.includes('react-dom/server')
|
|
613
558
|
) {
|
|
614
|
-
return true
|
|
615
|
-
}
|
|
616
|
-
// Only disable side effects for specific safe modules
|
|
617
|
-
if (id.includes('node_modules') && !id.includes('react')) {
|
|
618
559
|
return false
|
|
619
560
|
}
|
|
620
|
-
return
|
|
561
|
+
return false
|
|
621
562
|
},
|
|
622
563
|
unknownGlobalSideEffects: false,
|
|
623
564
|
}
|
|
624
565
|
|
|
625
|
-
const existingExternal = config.build.rolldownOptions
|
|
566
|
+
const existingExternal = config.build.rolldownOptions.external || []
|
|
626
567
|
const reactDomExternals = [
|
|
627
568
|
'react-dom/profiling',
|
|
628
569
|
'react-dom/test-utils',
|
|
@@ -636,10 +577,6 @@ if (import.meta.hot) {
|
|
|
636
577
|
'react/cjs/react.production.min.js',
|
|
637
578
|
'react-dom/cjs/react-dom.development.js',
|
|
638
579
|
'react-dom/cjs/react-dom.production.min.js',
|
|
639
|
-
'react-dom/src/client/ReactDOMRoot.js',
|
|
640
|
-
'react-dom/src/events/plugins',
|
|
641
|
-
'react-dom/src/shared/HTMLDOMPropertyConfig.js',
|
|
642
|
-
'react-dom/src/shared/DOMPropertyOperations.js',
|
|
643
580
|
]
|
|
644
581
|
|
|
645
582
|
if (Array.isArray(existingExternal)) {
|
|
@@ -651,11 +588,7 @@ if (import.meta.hot) {
|
|
|
651
588
|
}
|
|
652
589
|
else if (typeof existingExternal === 'function') {
|
|
653
590
|
const originalExternal = existingExternal
|
|
654
|
-
config.build.rolldownOptions.external = (
|
|
655
|
-
id,
|
|
656
|
-
parentId,
|
|
657
|
-
isResolved,
|
|
658
|
-
) => {
|
|
591
|
+
config.build.rolldownOptions.external = (id, parentId, isResolved) => {
|
|
659
592
|
if (reactDomExternals.includes(id))
|
|
660
593
|
return true
|
|
661
594
|
return originalExternal(id, parentId, isResolved)
|
|
@@ -670,7 +603,7 @@ if (import.meta.hot) {
|
|
|
670
603
|
].filter(Boolean)
|
|
671
604
|
}
|
|
672
605
|
|
|
673
|
-
config.build.minify =
|
|
606
|
+
config.build.minify = config.build.minify !== false ? 'terser' : false
|
|
674
607
|
config.build.target = config.build.target || [
|
|
675
608
|
'es2020',
|
|
676
609
|
'edge88',
|
|
@@ -680,47 +613,18 @@ if (import.meta.hot) {
|
|
|
680
613
|
]
|
|
681
614
|
config.build.cssMinify
|
|
682
615
|
= config.build.cssMinify !== false ? 'esbuild' : false
|
|
683
|
-
config.build.cssCodeSplit = true
|
|
684
|
-
config.build.assetsInlineLimit = 4096
|
|
685
|
-
config.build.chunkSizeWarningLimit = 1000
|
|
686
616
|
config.build.sourcemap
|
|
687
|
-
= config.build.sourcemap !== undefined ? config.build.sourcemap :
|
|
617
|
+
= config.build.sourcemap !== undefined ? config.build.sourcemap : false
|
|
688
618
|
|
|
689
619
|
config.build.terserOptions = config.build.terserOptions || {
|
|
690
620
|
compress: {
|
|
691
621
|
drop_console: true,
|
|
692
622
|
drop_debugger: true,
|
|
693
|
-
pure_funcs: [
|
|
694
|
-
|
|
695
|
-
'console.info',
|
|
696
|
-
'console.debug',
|
|
697
|
-
'console.warn',
|
|
698
|
-
'invariant',
|
|
699
|
-
'warning',
|
|
700
|
-
'__DEV__',
|
|
701
|
-
'ReactDOM.render',
|
|
702
|
-
'ReactDOM.unmountComponentAtNode',
|
|
703
|
-
'ReactDOM.findDOMNode',
|
|
704
|
-
'ReactDOM.createPortal',
|
|
705
|
-
],
|
|
706
|
-
passes: 3,
|
|
707
|
-
unsafe: true,
|
|
708
|
-
unsafe_comps: true,
|
|
709
|
-
unsafe_Function: true,
|
|
710
|
-
unsafe_math: true,
|
|
711
|
-
unsafe_symbols: true,
|
|
712
|
-
unsafe_methods: true,
|
|
713
|
-
unsafe_proto: true,
|
|
714
|
-
unsafe_regexp: true,
|
|
715
|
-
unsafe_undefined: true,
|
|
716
|
-
dead_code: true,
|
|
717
|
-
side_effects: false,
|
|
623
|
+
pure_funcs: ['console.log', 'console.info', 'console.debug'],
|
|
624
|
+
passes: 2,
|
|
718
625
|
},
|
|
719
626
|
mangle: {
|
|
720
627
|
safari10: true,
|
|
721
|
-
properties: {
|
|
722
|
-
regex: /^_/,
|
|
723
|
-
},
|
|
724
628
|
},
|
|
725
629
|
format: {
|
|
726
630
|
comments: false,
|
|
@@ -762,19 +666,8 @@ if (import.meta.hot) {
|
|
|
762
666
|
)['client-components'] = 'virtual:rsc-client-components'
|
|
763
667
|
}
|
|
764
668
|
|
|
765
|
-
config.environments.client.build.
|
|
766
|
-
= config.environments.client.build.
|
|
767
|
-
if (
|
|
768
|
-
Array.isArray(
|
|
769
|
-
config.environments.client.build.rolldownOptions.plugins,
|
|
770
|
-
)
|
|
771
|
-
) {
|
|
772
|
-
config.environments.client.build.rolldownOptions.plugins.push(
|
|
773
|
-
minify(),
|
|
774
|
-
)
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
config.environments.client.build.minify = true
|
|
669
|
+
config.environments.client.build.minify
|
|
670
|
+
= config.environments.client.build.minify !== false ? 'esbuild' : false
|
|
778
671
|
config.environments.client.build.target = config.environments.client
|
|
779
672
|
.build
|
|
780
673
|
.target || [
|
|
@@ -785,8 +678,6 @@ if (import.meta.hot) {
|
|
|
785
678
|
'safari14',
|
|
786
679
|
]
|
|
787
680
|
config.environments.client.build.cssMinify = 'esbuild'
|
|
788
|
-
config.environments.client.build.cssCodeSplit = true
|
|
789
|
-
config.environments.client.build.assetsInlineLimit = 4096
|
|
790
681
|
config.environments.client.build.rolldownOptions.treeshake = {
|
|
791
682
|
moduleSideEffects: false,
|
|
792
683
|
unknownGlobalSideEffects: false,
|
|
@@ -800,37 +691,28 @@ if (import.meta.hot) {
|
|
|
800
691
|
? config.environments.client.build.rolldownOptions.output[0] || {}
|
|
801
692
|
: config.environments.client.build.rolldownOptions.output
|
|
802
693
|
|
|
803
|
-
clientOutputConfig.manualChunks
|
|
804
|
-
|
|
805
|
-
id
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
return 'router'
|
|
826
|
-
}
|
|
827
|
-
if (id.includes('markdown-it') || id.includes('shiki')) {
|
|
828
|
-
return 'vendor'
|
|
829
|
-
}
|
|
830
|
-
if (id.includes('node_modules')) {
|
|
831
|
-
return 'vendor'
|
|
832
|
-
}
|
|
833
|
-
}
|
|
694
|
+
clientOutputConfig.manualChunks
|
|
695
|
+
= clientOutputConfig.manualChunks
|
|
696
|
+
|| ((id) => {
|
|
697
|
+
if (id.includes('react-dom')) {
|
|
698
|
+
return 'react-dom'
|
|
699
|
+
}
|
|
700
|
+
if (id.includes('react') && !id.includes('react-dom')) {
|
|
701
|
+
return 'react'
|
|
702
|
+
}
|
|
703
|
+
if (
|
|
704
|
+
id.includes('rari')
|
|
705
|
+
&& (id.includes('router') || id.includes('navigation'))
|
|
706
|
+
) {
|
|
707
|
+
return 'router'
|
|
708
|
+
}
|
|
709
|
+
if (id.includes('markdown-it') || id.includes('shiki')) {
|
|
710
|
+
return 'vendor'
|
|
711
|
+
}
|
|
712
|
+
if (id.includes('node_modules')) {
|
|
713
|
+
return 'vendor'
|
|
714
|
+
}
|
|
715
|
+
})
|
|
834
716
|
|
|
835
717
|
clientOutputConfig.format = clientOutputConfig.format || 'es'
|
|
836
718
|
clientOutputConfig.minify = true
|
|
@@ -855,20 +737,6 @@ if (import.meta.hot) {
|
|
|
855
737
|
return null
|
|
856
738
|
}
|
|
857
739
|
|
|
858
|
-
if (code.includes('react-dom')) {
|
|
859
|
-
code = code.replace(
|
|
860
|
-
/import\s+ReactDOM\s+from\s+['"]react-dom\/client['"];?/g,
|
|
861
|
-
'import { createRoot, hydrateRoot } from \'react-dom/client\';',
|
|
862
|
-
)
|
|
863
|
-
code = code.replace(
|
|
864
|
-
/import\s+ReactDOM\s+from\s+['"]react-dom['"];?/g,
|
|
865
|
-
'import { createRoot, hydrateRoot } from \'react-dom/client\';',
|
|
866
|
-
)
|
|
867
|
-
|
|
868
|
-
code = code.replace(/ReactDOM\.createRoot/g, 'createRoot')
|
|
869
|
-
code = code.replace(/ReactDOM\.hydrateRoot/g, 'hydrateRoot')
|
|
870
|
-
}
|
|
871
|
-
|
|
872
740
|
const environment = (this as any).environment
|
|
873
741
|
|
|
874
742
|
if (hasTopLevelDirective(code, 'use client')) {
|
|
@@ -1584,6 +1452,7 @@ export const __CLIENT_REFERENCE_REGISTRY__ = clientReferenceRegistry;
|
|
|
1584
1452
|
export const __SERVER_REFERENCE_REGISTRY__ = serverReferenceRegistry;
|
|
1585
1453
|
export const __CLIENT_COMPONENT_REGISTRY__ = clientComponentRegistry;
|
|
1586
1454
|
|
|
1455
|
+
// Module map for React Server Components
|
|
1587
1456
|
export function createClientModuleMap() {
|
|
1588
1457
|
const moduleMap = {};
|
|
1589
1458
|
|
|
@@ -1609,6 +1478,7 @@ export function createClientModuleMap() {
|
|
|
1609
1478
|
return `
|
|
1610
1479
|
import React, { useState, useEffect, Suspense } from 'react';
|
|
1611
1480
|
|
|
1481
|
+
// Client component registration for RSC system compatibility
|
|
1612
1482
|
if (typeof globalThis.__clientComponents === 'undefined') {
|
|
1613
1483
|
globalThis.__clientComponents = {};
|
|
1614
1484
|
}
|
|
@@ -1626,6 +1496,7 @@ export function registerClientComponent(componentFunction, id, exportName) {
|
|
|
1626
1496
|
|
|
1627
1497
|
const componentId = componentName;
|
|
1628
1498
|
|
|
1499
|
+
// Register in global registry for RSC traversal
|
|
1629
1500
|
globalThis.__clientComponents[componentId] = {
|
|
1630
1501
|
id: componentId,
|
|
1631
1502
|
path: id,
|
|
@@ -2386,7 +2257,7 @@ class RscClient {
|
|
|
2386
2257
|
const processedChildren = value.map((child, index) => {
|
|
2387
2258
|
const result = this.reconstructElementFromRscData(child, modules);
|
|
2388
2259
|
return result;
|
|
2389
|
-
}).filter(child => child !== null && child !== undefined);
|
|
2260
|
+
}).filter(child => child !== null && child !== undefined); // Remove null/undefined children
|
|
2390
2261
|
|
|
2391
2262
|
if (processedChildren.length === 0) {
|
|
2392
2263
|
processed[key] = null;
|
|
@@ -2531,6 +2402,7 @@ function ServerComponentWrapper({
|
|
|
2531
2402
|
}
|
|
2532
2403
|
|
|
2533
2404
|
function createServerComponentWrapper(componentName, importPath) {
|
|
2405
|
+
// Use a global refresh counter to force re-mounting when components change
|
|
2534
2406
|
let globalRefreshCounter = 0;
|
|
2535
2407
|
|
|
2536
2408
|
if (typeof window !== 'undefined') {
|
|
@@ -2544,6 +2416,7 @@ function createServerComponentWrapper(componentName, importPath) {
|
|
|
2544
2416
|
const ServerComponent = (props) => {
|
|
2545
2417
|
const [mountKey, setMountKey] = useState(globalRefreshCounter);
|
|
2546
2418
|
|
|
2419
|
+
// Force re-mount when component is invalidated
|
|
2547
2420
|
useEffect(() => {
|
|
2548
2421
|
const handleRscInvalidate = (event) => {
|
|
2549
2422
|
const detail = event.detail;
|
|
@@ -2564,7 +2437,7 @@ function createServerComponentWrapper(componentName, importPath) {
|
|
|
2564
2437
|
return React.createElement(Suspense, {
|
|
2565
2438
|
fallback: null
|
|
2566
2439
|
}, React.createElement(ServerComponentWrapper, {
|
|
2567
|
-
key: componentName + '-' + mountKey,
|
|
2440
|
+
key: componentName + '-' + mountKey, // Force re-mount with key change
|
|
2568
2441
|
componentId: componentName,
|
|
2569
2442
|
props: props,
|
|
2570
2443
|
fallback: null
|
|
@@ -2581,7 +2454,9 @@ function createServerComponentWrapper(componentName, importPath) {
|
|
|
2581
2454
|
export const fetchServerComponent = (componentId, props) =>
|
|
2582
2455
|
rscClient.fetchServerComponent(componentId, props);
|
|
2583
2456
|
|
|
2457
|
+
// Helper function to check if a file is a server component (client-side)
|
|
2584
2458
|
function isServerComponent(filePath) {
|
|
2459
|
+
// Simple client-side check based on file path patterns
|
|
2585
2460
|
return filePath && (
|
|
2586
2461
|
filePath.includes('ServerWithClient') ||
|
|
2587
2462
|
filePath.includes('server') ||
|
|
@@ -2589,26 +2464,32 @@ function isServerComponent(filePath) {
|
|
|
2589
2464
|
);
|
|
2590
2465
|
}
|
|
2591
2466
|
|
|
2467
|
+
// HMR support for RSC cache invalidation
|
|
2592
2468
|
if (import.meta.hot) {
|
|
2469
|
+
// Listen for Vite's beforeFullReload event for server components
|
|
2593
2470
|
import.meta.hot.on('vite:beforeFullReload', async (data) => {
|
|
2594
2471
|
if (data?.path && isServerComponent(data.path)) {
|
|
2472
|
+
// Immediately invalidate cache and trigger re-registration before reload
|
|
2595
2473
|
await invalidateRscCache({ filePath: data.path, forceReload: true });
|
|
2596
2474
|
}
|
|
2597
2475
|
});
|
|
2598
2476
|
|
|
2599
2477
|
|
|
2600
2478
|
|
|
2479
|
+
// Helper function to invalidate RSC cache and trigger component re-registration
|
|
2601
2480
|
async function invalidateRscCache(data) {
|
|
2602
2481
|
const filePath = data?.filePath || data;
|
|
2603
2482
|
|
|
2483
|
+
// Wait for server to be ready
|
|
2604
2484
|
const waitForServerReady = async () => {
|
|
2605
|
-
for (let i = 0; i < 20; i++) {
|
|
2485
|
+
for (let i = 0; i < 20; i++) { // Try for up to 2 seconds
|
|
2606
2486
|
try {
|
|
2607
2487
|
const response = await fetch('/_rsc_status');
|
|
2608
2488
|
if (response.ok) {
|
|
2609
2489
|
return true;
|
|
2610
2490
|
}
|
|
2611
2491
|
} catch (e) {
|
|
2492
|
+
// Server not ready yet
|
|
2612
2493
|
}
|
|
2613
2494
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
2614
2495
|
}
|
|
@@ -2617,8 +2498,10 @@ if (import.meta.hot) {
|
|
|
2617
2498
|
|
|
2618
2499
|
const serverReady = await waitForServerReady();
|
|
2619
2500
|
if (serverReady) {
|
|
2501
|
+
// Clear client-side RSC cache immediately
|
|
2620
2502
|
rscClient.clearCache();
|
|
2621
2503
|
|
|
2504
|
+
// Trigger immediate server component re-registration
|
|
2622
2505
|
try {
|
|
2623
2506
|
await fetch('/api/rsc/hmr-register', {
|
|
2624
2507
|
method: 'POST',
|
|
@@ -2630,10 +2513,14 @@ if (import.meta.hot) {
|
|
|
2630
2513
|
})
|
|
2631
2514
|
});
|
|
2632
2515
|
|
|
2516
|
+
// Wait a bit for the server to re-register the component
|
|
2517
|
+
// The server now immediately reads and re-registers the component
|
|
2633
2518
|
await new Promise(resolve => setTimeout(resolve, 300));
|
|
2634
2519
|
} catch (error) {
|
|
2520
|
+
// Fallback to existing timeout-based approach
|
|
2635
2521
|
}
|
|
2636
2522
|
|
|
2523
|
+
// Trigger re-render of active server components
|
|
2637
2524
|
if (typeof window !== 'undefined') {
|
|
2638
2525
|
const event = new CustomEvent('rari:rsc-invalidate', {
|
|
2639
2526
|
detail: { filePath }
|
|
@@ -2718,108 +2605,6 @@ ${registrations.join('\n')}
|
|
|
2718
2605
|
return [mainPlugin, serverBuildPlugin]
|
|
2719
2606
|
}
|
|
2720
2607
|
|
|
2721
|
-
export function createReactDOMOptimization() {
|
|
2722
|
-
return {
|
|
2723
|
-
build: {
|
|
2724
|
-
rollupOptions: {
|
|
2725
|
-
output: {
|
|
2726
|
-
manualChunks: (id: string) => {
|
|
2727
|
-
if (
|
|
2728
|
-
id.includes('node_modules/react-dom')
|
|
2729
|
-
|| id.includes('react-dom/client')
|
|
2730
|
-
|| id.includes('react-dom/server')
|
|
2731
|
-
|| id.includes('react-dom/')
|
|
2732
|
-
) {
|
|
2733
|
-
return 'react-dom'
|
|
2734
|
-
}
|
|
2735
|
-
|
|
2736
|
-
if (
|
|
2737
|
-
(id.includes('node_modules/react') || id.includes('react/'))
|
|
2738
|
-
&& !id.includes('react-dom')
|
|
2739
|
-
) {
|
|
2740
|
-
return 'react'
|
|
2741
|
-
}
|
|
2742
|
-
|
|
2743
|
-
if (id.includes('scheduler') && id.includes('node_modules')) {
|
|
2744
|
-
return 'scheduler'
|
|
2745
|
-
}
|
|
2746
|
-
|
|
2747
|
-
if (id.includes('markdown-it') || id.includes('shiki')) {
|
|
2748
|
-
return 'vendor'
|
|
2749
|
-
}
|
|
2750
|
-
|
|
2751
|
-
if (id.includes('node_modules')) {
|
|
2752
|
-
return 'vendor'
|
|
2753
|
-
}
|
|
2754
|
-
},
|
|
2755
|
-
},
|
|
2756
|
-
treeshake: {
|
|
2757
|
-
moduleSideEffects: (id: string) => {
|
|
2758
|
-
if (id.includes('.css') || id.includes('polyfill')) {
|
|
2759
|
-
return true
|
|
2760
|
-
}
|
|
2761
|
-
if (
|
|
2762
|
-
id.includes('react-dom')
|
|
2763
|
-
|| id.includes('react')
|
|
2764
|
-
|| id.includes('scheduler')
|
|
2765
|
-
|| id.includes('react-dom/client')
|
|
2766
|
-
|| id.includes('react-dom/server')
|
|
2767
|
-
) {
|
|
2768
|
-
return false
|
|
2769
|
-
}
|
|
2770
|
-
return false
|
|
2771
|
-
},
|
|
2772
|
-
unknownGlobalSideEffects: false,
|
|
2773
|
-
},
|
|
2774
|
-
},
|
|
2775
|
-
minify: 'terser',
|
|
2776
|
-
target: ['es2020', 'edge88', 'firefox78', 'chrome87', 'safari14'],
|
|
2777
|
-
cssMinify: 'esbuild',
|
|
2778
|
-
sourcemap: false,
|
|
2779
|
-
terserOptions: {
|
|
2780
|
-
compress: {
|
|
2781
|
-
drop_console: true,
|
|
2782
|
-
drop_debugger: true,
|
|
2783
|
-
pure_funcs: [
|
|
2784
|
-
'console.log',
|
|
2785
|
-
'console.info',
|
|
2786
|
-
'console.debug',
|
|
2787
|
-
'console.warn',
|
|
2788
|
-
'invariant',
|
|
2789
|
-
'warning',
|
|
2790
|
-
'__DEV__',
|
|
2791
|
-
'ReactDOM.render',
|
|
2792
|
-
'ReactDOM.unmountComponentAtNode',
|
|
2793
|
-
'ReactDOM.findDOMNode',
|
|
2794
|
-
'ReactDOM.createPortal',
|
|
2795
|
-
],
|
|
2796
|
-
passes: 3,
|
|
2797
|
-
unsafe: true,
|
|
2798
|
-
unsafe_comps: true,
|
|
2799
|
-
unsafe_Function: true,
|
|
2800
|
-
unsafe_math: true,
|
|
2801
|
-
unsafe_symbols: true,
|
|
2802
|
-
unsafe_methods: true,
|
|
2803
|
-
unsafe_proto: true,
|
|
2804
|
-
unsafe_regexp: true,
|
|
2805
|
-
unsafe_undefined: true,
|
|
2806
|
-
dead_code: true,
|
|
2807
|
-
side_effects: false,
|
|
2808
|
-
},
|
|
2809
|
-
mangle: {
|
|
2810
|
-
safari10: true,
|
|
2811
|
-
properties: {
|
|
2812
|
-
regex: /^_/,
|
|
2813
|
-
},
|
|
2814
|
-
},
|
|
2815
|
-
format: {
|
|
2816
|
-
comments: false,
|
|
2817
|
-
},
|
|
2818
|
-
},
|
|
2819
|
-
},
|
|
2820
|
-
}
|
|
2821
|
-
}
|
|
2822
|
-
|
|
2823
2608
|
export function defineRariConfig(
|
|
2824
2609
|
config: UserConfig & { plugins?: Plugin[] },
|
|
2825
2610
|
): UserConfig {
|