Skip to content

Fix React 19 Activity component support: preserve view state across hide/show cycles#10016

Open
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-react-19-activity-support
Open

Fix React 19 Activity component support: preserve view state across hide/show cycles#10016
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-react-19-activity-support

Conversation

Copy link
Contributor

Copilot AI commented Feb 20, 2026

React 19's <Activity> component preserves React state but runs effect cleanup/re-setup on hide/show, causing DeckGL to destroy and recreate its Deck instance — resetting initialViewState and losing user pan/zoom.

Change List

  • Save view state on cleanup: before finalize(), snapshot deck.viewState (the internally-tracked uncontrolled view state) into a savedViewState field on the persistent thisRef
  • Restore on re-init: if savedViewState is set when the effect re-runs, pass it as initialViewState to the new Deck instance, then clear it
  • Controlled mode unaffected: deck.viewState is null in controlled (props.viewState) mode, so the truthy check correctly skips restoration
// cleanup
thisRef.savedViewState = thisRef.deck.viewState; // null in controlled mode
thisRef.deck.finalize();

// setup
if (thisRef.savedViewState) {
  initProps.initialViewState = thisRef.savedViewState;
  thisRef.savedViewState = undefined;
}
thisRef.deck = createDeckInstance(thisRef, DeckClass, initProps);
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug] React 19 Activity component support</issue_title>
<issue_description>### Description

Summary

deck.gl's React component doesn't properly support React 19's <Activity> component. When a <DeckGL> component is hidden via Activity and then shown again, the view state resets to initialViewState, losing any user interactions (pan/zoom).

Background

React 19.2 introduced the <Activity> component which hides components without unmounting them. However, Activity has a specific behavior: effect cleanup functions run when hidden, and effects re-run when visible again (while React state is preserved).

Related

Flavors

  • Script tag
  • React
  • Python/Jupyter notebook
  • MapboxOverlay
  • GoogleMapsOverlay
  • CARTO
  • ArcGIS

Expected Behavior

Deck should retain state in the hidden activity mode.

Steps to Reproduce

https://github.com/mohadib/deck-activity

This example has 2 maps and a div you can toggle between. One map uses an Activity, and the other uses css display: none when hidden. The css hiding retains state, the activity does not.

Root Cause

The DeckGL component's initialization effect (modules/react/src/deckgl.ts:189-199):

useEffect(() => {
  thisRef.deck = createDeckInstance(thisRef, DeckClass, {...});
  return () => thisRef.deck?.finalize();
}, []);

When Activity hides the component:

  1. Cleanup runs → finalize() destroys the Deck instance and its internal view state
  2. When shown again → A new Deck instance is created with the original initialViewState
  3. User's pan/zoom changes are lost

Environment

  • Framework version: 9.2
  • Browser: Chrome
  • OS: MacOS

Logs

No response</issue_description>

<agent_instructions>i bet you cant one shot this.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…ss hide/show cycles

Co-authored-by: charlieforward9 <62311337+charlieforward9@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix React 19 Activity component support in deck.gl Fix React 19 Activity component support: preserve view state across hide/show cycles Feb 20, 2026
@charlieforward9
Copy link
Collaborator

charlieforward9 commented Feb 20, 2026

I imagine there is a cleaner way to do this in a future version that permanently changes the functionality but for now this would be backwards compatible

@mohadib

@chrisgervang
Copy link
Collaborator

I was wondering if the issue is isolated to viewState or if other props were resetting as well?

@charlieforward9
Copy link
Collaborator

I havent messed with the Activity API yet - @mohadib can you isolate the issue?

@charlieforward9 charlieforward9 marked this pull request as ready for review February 20, 2026 20:59
@coveralls
Copy link

Coverage Status

coverage: 91.053% (-0.003%) from 91.056%
when pulling 623e905 on copilot/fix-react-19-activity-support
into 9b4f613 on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] React 19 Activity component support

4 participants