Open code, practice, and notes →
Download source with English comments · for reading
Vue · 24 Shallow Reactivity and External Objects
Series contents · Technology map
Stage: Canvas Integration and Update Verification · Editable example · Storage ID: vue-step-24
Goals and learning outcomes
- Consumers read the new handle when the renderer handle is replaced.
- Template statistics do not update on every frame change.
Prerequisites
Unit 24 builds on the work and experiment records from Unit 23.
Key concepts and explanations
shallowRef
shallowRef tracks replacement of .value without deeply wrapping the inner object. Consider it when managing lifetimes of external objects such as Three.js objects.
Explicit notification
An internal mutation does not always require a Vue update. For an on-screen summary, notify through a separate ref or explicit replacement.
Practice setup
First check the execution scope guidance on the example screen. The following is the preparation environment for extending the assignment in a separate project. Use .vue SFCs and script setup in a separate Vue Vite project. Record package versions and the lockfile, and run on the development server. The built-in Vue examples use the h function and are not a general-purpose SFC compiler.
The linked example is a starting point. It does not implement every task below. Complete work beyond its supported scope in a separate project.
Practice tasks
- Store an external renderer handle in a shallowRef in src/useRenderer.js.
- Change the scene object's internal rotation in the loop, and display separate low-frequency statistics in the UI.
- Compare object identity and UI update logs against a deep ref control.
Variables to observe
| Variable | Baseline | Change | Expected change / hypothesis |
|---|---|---|---|
| Storage method | Deep ref | shallowRef | Internal changes to the external object are excluded from Vue's deep tracking. |
Predictions in this table are not measured results. Change one condition at a time and record why the actual result differs.
Completion criteria
- Consumers read the new handle when the renderer handle is replaced.
- Template statistics do not update on every frame change.
Self-check
- What options update the UI after a shallowRef's internals change?
- What do markRaw and shallowRef control differently?
Official references
Linked example and execution scope
Example source · Runtime environments and limits
This is an experiment with actual Vue reactivity and render functions. Check SFC templates in an external compilation environment.
Source code and records are not overwritten automatically. Resetting an existing example also preserves your notes.
Next learning
Previous: Separating Frame Values from UI Values · Next: Observing Vue Performance