ezfw-core 1.0.62 → 1.0.63

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.
@@ -11,7 +11,7 @@ import { ComponentAnalyzer, analyzer } from './analyzer.js';
11
11
  export interface RenderContext {
12
12
  // Component registry
13
13
  registry: Map<string, ComponentDefinition>;
14
- // CSS classes collected during render
14
+ // CSS module names collected during render (e.g., 'LinearPageNav')
15
15
  styles: Set<string>;
16
16
  // Islands found during render (for hydration script)
17
17
  islands: IslandData[];
@@ -171,6 +171,11 @@ export class StaticHtmlRenderer {
171
171
  props: Record<string, unknown>,
172
172
  ctx: RenderContext
173
173
  ): Promise<string> {
174
+ // Track CSS module for this component
175
+ if (definition.css && typeof definition.css === 'string') {
176
+ ctx.styles.add(definition.css);
177
+ }
178
+
174
179
  let config: ComponentConfig;
175
180
 
176
181
  // Get component config from template or items
@@ -861,8 +861,8 @@ async function renderPageDev(
861
861
  // Render body
862
862
  const body = await renderer.renderPage(page.name, definition, ctx);
863
863
 
864
- // Generate hydration script
865
- const scripts = generateHydrationScript(ctx.islands, true);
864
+ // Generate hydration script (pass CSS modules collected during render)
865
+ const scripts = generateHydrationScript(ctx.islands, true, [...ctx.styles]);
866
866
 
867
867
  // Generate head meta tags
868
868
  const title = page.title || page.name;
@@ -969,8 +969,8 @@ async function renderPageBuild(
969
969
  // Render body
970
970
  const body = await renderer.renderPage(page.name, definition, ctx);
971
971
 
972
- // Generate hydration script
973
- const scripts = generateHydrationScript(ctx.islands, false);
972
+ // Generate hydration script (pass CSS modules collected during render)
973
+ const scripts = generateHydrationScript(ctx.islands, false, [...ctx.styles]);
974
974
 
975
975
  // Generate head meta tags
976
976
  const title = page.title || page.name;
@@ -990,24 +990,34 @@ async function renderPageBuild(
990
990
  */
991
991
  function generateHydrationScript(
992
992
  islands: Array<{ id: string; component: string; props: Record<string, unknown> }>,
993
- isDev: boolean
993
+ isDev: boolean,
994
+ cssModules: string[] = []
994
995
  ): string {
995
- if (islands.length === 0) {
996
- return '';
997
- }
998
-
999
996
  const islandsJson = JSON.stringify(islands);
1000
- // In dev mode, use path that Vite's dev server can resolve from node_modules
1001
- const runtimePath = isDev ? '/node_modules/ezfw-core/islands/runtime.ts' : '/assets/islands-runtime.js';
997
+ const cssModulesJson = JSON.stringify(cssModules);
998
+
999
+ // In dev mode, use local ez/ path (framework is in project, not node_modules)
1000
+ const runtimePath = isDev ? '/ez/islands/runtime.ts' : '/assets/islands-runtime.js';
1002
1001
  // Use hydrate.js for SSR - it doesn't import CSS directly, avoiding MIME type issues
1003
1002
  const frameworkPath = isDev ? '/hydrate.js' : '/assets/hydrate.js';
1004
1003
 
1004
+ // Generate CSS loading code - load CSS modules BEFORE rendering
1005
+ const cssLoadingCode = cssModules.length > 0 ? `
1006
+ // Load CSS modules used by SSR-rendered components
1007
+ const cssModules = ${cssModulesJson};
1008
+ for (const cssName of cssModules) {
1009
+ await ez.resolveStyles(cssName);
1010
+ }
1011
+ console.log('[Ez SSR] Loaded ${cssModules.length} CSS module(s):', cssModules);` : '';
1012
+
1005
1013
  return `<script type="module">
1006
1014
  // Ez Islands v2 - Set SSR flag and islands data BEFORE loading runtime
1007
1015
  window.__EZ_SSR_MODE__ = true;
1008
1016
  window.__EZ_ISLANDS__ = ${islandsJson};
1009
- // Load framework first, then runtime (which auto-executes hydration)
1017
+ // Load framework first
1010
1018
  await import('${frameworkPath}');
1019
+ ${cssLoadingCode}
1020
+ // Then load runtime for island hydration
1011
1021
  await import('${runtimePath}');
1012
1022
  </script>`;
1013
1023
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ezfw-core",
3
- "version": "1.0.62",
3
+ "version": "1.0.63",
4
4
  "description": "Ez Framework - A declarative component framework for building modern web applications",
5
5
  "type": "module",
6
6
  "main": "./core/ez.ts",