Repository navigation
docs: warn against per-render state keyed by component ID in extensions - #1649
Merged
Merged
Conversation
Follow-up to the CacheExtension leak fixed in #1648. That leak was an instance of a general trap: an extension that stores per-render state in `on_component_input` (in a dict on the extension, keyed by component ID) and cleans it up in `on_component_rendered` will leak whenever a later extension short-circuits the render, because `on_component_rendered` never fires for that component. Document the trap and the fix (bind the state to the component lifetime, e.g. the per-component extension config) in two places: - A `!!! warning` on the `on_component_input` hook docstring. - A "Storing data for a single render" section in the extensions guide, written for readers new to extensions. No code behavior change. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Closed
Contributor
Performance Benchmark ResultsComparing PR changes against master branch: Benchmarks that have stayed the same:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(Opus 4.8)
Summary
Documentation follow-up to #1648 (the
CacheExtensionshort-circuit leak).That leak was a specific instance of a general trap for extension authors: if an extension stores per-render state in
on_component_input(in a dict on the extension, keyed bycomponent_id) and removes it inon_component_rendered, it leaks whenever a later extension short-circuits the render — becauseon_component_renderednever fires for that component, so the entry is never removed. One orphaned entry accumulates per skipped render.This PR documents the trap and the fix (bind per-render state to the component's lifetime, e.g. its per-component extension config), so users don't reintroduce the same bug in their own extensions.
Changes
on_component_inputdocstring (extension.py) — a!!! warningexplaining that short-circuiting skipson_component_data/on_component_rendered, and that per-render state must be tied to the component lifetime.docs/concepts/advanced/extensions.md) — a new "Storing data for a single render" section with ❌/✅ examples, written for readers new to extensions. It sits next to the existing "Pass slot metadata" anti-pattern, which is the same shape for slots.No code behavior change.
Checks
uv run ruff check ./ruff format --check— cleanuv run mypy src/django_components/extension.py— cleanuv run mkdocs build --strict— clean (link anchors verified againstdocs/reference/extension_hooks.md)🤖 Generated with Claude Code