deferred-di-reflect-metadata-optimization

Removes redundant reflect-metadata imports from deferred tsyringe DI entry bundles.

1|Updated Jun 9, 2026
One-click install
npx skills add https://github.com/VilnaCRM-Org/claude-plugins --skill deferred-di-reflect-metadata-optimization-vilnacrm-org
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: deferred-di-reflect-metadata-optimization
Source: https://github.com/VilnaCRM-Org/claude-plugins/tree/main/plugins/react-frontend-sdlc/skills/deferred-di-reflect-metadata-optimization
Command: npx skills add https://github.com/VilnaCRM-Org/claude-plugins --skill deferred-di-reflect-metadata-optimization-vilnacrm-org

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? When a tsyringe application loads its DI container behind a dynamic import, the eager import 'reflect-metadata'; in the client entry is redundant yet still ships roughly 16 KB gzip on the critical render path, hurting mobile Lighthouse performance scores. ## Core Features & Use Cases - Precondition auditing: Walks the entry file's static import closure to confirm no decorated class is reached eagerly before removing the import. - Regression pinning: Adds a unit test asserting neither reflect-metadata nor the composition-root import appears in the client entry source. - Measured verification: Rebuilds through the configured bundler, reads the bundle report, and runs the mobile Lighthouse audit to confirm roughly +0.03 performance lift. - Use Case: A React SPA misses its mobile Lighthouse budget by a few hundredths; after confirming the composition root loads the container via dynamic import, the entry shim is deleted, the contract test is pinned, and the entrypoint shrinks by about 16 KB gzip. ## Quick Start Check whether my client entry eagerly imports reflect-metadata while the DI composition root loads behind a dynamic import, and if so remove the redundant import and pin it with a test.

Frequently Asked Questions about deferred-di-reflect-metadata-optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I remove reflect-metadata from my entry bundle with tsyringe?▼

Delete the eager `import 'reflect-metadata';` from the client entry only when the DI composition root loads the container behind a dynamic import and imports the shim itself. Then pin the removal with a unit test asserting the entry source contains neither import.

How much bundle size does removing reflect-metadata save?▼

Removing the eager reflect-metadata import takes roughly 16 KB gzip off the critical render path. The measured mobile Lighthouse lift is approximately +0.03 on the performance category, but always confirm with a bundle report since the number depends on what else the entry pulls in.

When is it unsafe to remove the reflect-metadata import?▼

It is unsafe when the entry file or anything in its static import closure declares or instantiates a decorated class such as one marked with @injectable(). In that case the eager import is load-bearing and removing it causes a runtime failure on first resolution.

Why does decorator resolution fail at runtime after removing the import?▼

Resolution fails because a decorated class was reachable through the entry's static import closure, so the metadata shim was still needed eagerly. Walk the full static closure before removal; the error only surfaces at runtime, not at build time.

Does this optimization apply to Next.js or component libraries?▼

No. Next.js app shapes and Storybook-first component libraries have no tsyringe DI container, so the skill is inapplicable. It targets React SPAs with a deferred composition root such as a dependency-injection-config module loaded via dynamic import.