fix(createPlugin): defer factory call to install time to prevent resource leaks#343
Conversation
|
commit: |
…t cross-talk The lazy factory runs once per install, so the same plugin object installed on multiple apps gets a distinct context each time. The persist watch closed over the shared `context` binding, so a later install reassigned the source out from under earlier apps' watchers. Capture the context locally in setup so each app's persist watch tracks its own instance. Adds regression tests for the duplicate-namespace install (second factory must not run) and the multi-app persist isolation case, and trims the inline comments.
|
Pushed a small follow-up directly to this branch as a maintainer edit (d7e6f3c), on top of your fix. What it addressesThe lazy-factory move is correct. One edge it left open is in Concretely: with a single Fix is one capture — Tests added
AlsoTrimmed the two inline comment blocks down to the why. Verified in |
Fixes #338
Problem
createXPlugin()(viacreatePluginContext) called the context factory at plugin-creation time — beforeapp.use()ever runs:This means:
useMediaQuery's hydration-deferral contract silently breaks on the plugin path — the factory runs outside any injection contextSolution
Move factory invocation inside the
providecallback so it runs at install time, not factory time:providealways runs beforesetup(enforced bycreatePlugin), so the definite assignment is safe. TheINSTALLEDguard ensuressetupnever runs without a priorprovidecall.createXContext(the standalone path) is unchanged — standalone contexts still create eagerly, which is correct.Test plan
createXPlugin()time