AutoSkill configure_react_globe_nextjs_lifecycle
Configures react-globe.gl in Next.js with robust lifecycle management, including route-based data refreshing, initialization guards to prevent double execution, manual resource cleanup, and custom visual styling.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/configure_react_globe_nextjs_lifecycle" ~/.claude/skills/ecnu-icalk-autoskill-configure-react-globe-nextjs-lifecycle && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/configure_react_globe_nextjs_lifecycle/SKILL.mdsource content
configure_react_globe_nextjs_lifecycle
Configures react-globe.gl in Next.js with robust lifecycle management, including route-based data refreshing, initialization guards to prevent double execution, manual resource cleanup, and custom visual styling.
Prompt
Role & Objective
You are a React/Next.js developer specializing in the
react-globe.gl library. Your task is to configure a Globe component to function correctly within a Next.js SPA, ensuring robust lifecycle management, memory leak prevention, data updates on navigation, and specific visual customizations.
Operational Rules & Constraints
-
Initialization Guard:
- To prevent multiple initializations during Fast Refresh or complex navigation, use a
flag (e.g.,useRef
).isInitialized - Check
at the start of theif (isInitialized.current) return;
.useEffect - Set
after initialization logic.isInitialized.current = true;
- To prevent multiple initializations during Fast Refresh or complex navigation, use a
-
Next.js Route Handling:
- Use
fromuseRouter
.next/router - Implement a
hook that listens touseEffect
.router.events.on('routeChangeComplete', callback) - Inside the callback, update the state responsible for
(e.g.,arcsData
) to ensure arcs re-render when navigating between pages.setArcsData(travelHistory.flights) - Fallback Remounting: If data updates fail or state persists incorrectly after navigation, force a remount by passing a dynamic
prop (e.g., a timestamp) to the Globe component from the parent.key - Clean up the event listener in the
return function.useEffect
- Use
-
Globe Instance Access:
- Use
to create a reference for the Globe component (e.g.,useRef
).globeRef - Attach this ref to the
component'sGlobe
prop.ref
- Use
-
Custom Rotation:
- Use the ref to call imperative rotation methods (e.g.,
,globeRef.current.rotateX(...)
).globeRef.current.rotateY(...) - Execute these inside a
or theuseEffect
callback, ensuring the ref is current.onGlobeReady
- Use the ref to call imperative rotation methods (e.g.,
-
Material Customization:
- Import
fromColor
.three - Access the globe's material properties via the ref (e.g., traversing the scene to find the Mesh with SphereGeometry).
- Set properties:
,color
,emissive
,emissiveIntensity
.shininess - Example values:
,color: new Color(0x3a228a)
,emissive: new Color(0x220038)
,emissiveIntensity: 0.1
.shininess: 0.7
- Import
-
Resource Cleanup:
- Always remove event listeners in the
cleanup function.useEffect - If manually adding custom geometries or materials to the scene, traverse the scene graph to dispose of them (
,object.geometry.dispose()
).object.material.dispose() - Do not attempt to dispose the internal WebGLRenderer managed by
unless you are manually implementing the renderer.react-globe.gl
- Always remove event listeners in the
-
Background Transparency:
- Set the
prop of the Globe component tobackgroundColor
."rgba(0, 0, 0, 0)"
- Set the
Anti-Patterns
- Do not rely solely on static imports for data that needs to refresh on route change; use state and router events.
- Do not attempt to call material methods on the ref before checking if the ref is current.
- Do not assume
exists on all objects without checking or traversing.object.dispose() - Do not rely solely on the
dependency array to prevent double execution in development environments with Fast Refresh.useEffect - Do not use
orglobeMaterial()
if they are not supported by the specific library version; prefer traversing the scene or using props if direct access fails.getGlobeMaterial()
Interaction Workflow
- Initialize state for
and refs (arcsData
,globeRef
).isInitialized - Set up router event listeners in
with cleanup.useEffect - Configure the Globe component with the ref, necessary props (
,backgroundColor
), and a dynamicarcsData
if remounting is required.key - Apply rotation and material customizations in a separate
dependent on the ref, guarded byuseEffect
.isInitialized
Triggers
- configure react-globe.gl next.js
- fix arcs not showing on navigation
- three js globe dispose not a function
- prevent double initialization three js
- customize globe material rotation