Skip to content

Fix browser refresh corner cases in multi-map lazy init (issue #1384)#1607

Merged
jumpinjackie merged 4 commits intomasterfrom
copilot/fix-corner-case-issue-1384
Mar 14, 2026
Merged

Fix browser refresh corner cases in multi-map lazy init (issue #1384)#1607
jumpinjackie merged 4 commits intomasterfrom
copilot/fix-corner-case-issue-1384

Conversation

Copy link
Contributor

Copilot AI commented Mar 14, 2026

After a browser refresh with a reused session, switching to maps that were never previously visited would trigger a blind DESCRIBERUNTIMEMAP for those maps — which fails because they were never created on the server in the previous session. A second corner case also existed where refreshing while a non-first map (e.g., Redding in a 3-map layout) was active would result in a blank "Loading..." screen.

Root Cause

canLazyLoad was gated on !sessionWasReused, so on refresh all maps were eagerly pushed through tryDescribeRuntimeMapAsync during init — including never-visited ones that don't exist in the session yet.

A second bug existed in the deferred-map routing: it always treated the first map by appdef position as the primary map to recover, rather than the map the user was actually viewing. With Redding (map 2) active at refresh time, Redding was deferred to pendingMapDefs and the app had no runtimeMap for the active map, causing the blank screen.

Changes

  • src/actions/init-mapguide.ts: Drop !sessionWasReused from canLazyLoad. Reorder the routing so pendingMapDefs deferral takes priority. Use initialActiveMap (from the ?map= URL param) to identify which map to eagerly recover on refresh — not just the first-by-position. Falls back to first-by-position if initialActiveMap is absent or doesn't match any map in the appdef.

    // Before
    const canLazyLoad = !isStateless && !sessionWasReused && mapDefItems.length > 1;
    if (sessionWasReused) { tryDescribe(all maps) }
    else if (canLazyLoad && !isFirstMapDef) { defer }
    
    // After
    const canLazyLoad = !isStateless && mapDefItems.length > 1;
    // isPrimaryMap = initialActiveMap match (reused session) OR first-by-position (new session)
    if (canLazyLoad && !isPrimaryMap) { defer }
    else if (sessionWasReused) { tryDescribe(active map only) }
    
  • src/actions/map.ts (activateMap): Switch from always calling createRuntimeMap to a describe-first, create-on-not-found pattern. Handles both the reused-session case (map already exists → DESCRIBE succeeds) and the never-visited case (DESCRIBE fails with MgResourceNotFoundException → fall back to CREATE).

  • test/actions/map.spec.ts: Add three new activateMap tests covering: DESCRIBE success, DESCRIBE→CREATE fallback on MgResourceNotFoundException, and graceful degradation on other errors.


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

…1384)

Co-authored-by: jumpinjackie <563860+jumpinjackie@users.noreply.github.com>
Copilot AI changed the title [WIP] [ISSUE-1384] Fix corner case that is not properly handled Fix browser refresh corner case in multi-map lazy init (issue #1384) Mar 14, 2026
Copilot AI requested a review from jumpinjackie March 14, 2026 14:57
@coveralls
Copy link

coveralls commented Mar 14, 2026

Coverage Status

coverage: 39.489% (+0.1%) from 39.365%
when pulling b62a7d0 on copilot/fix-corner-case-issue-1384
into 7a870e9 on master.

@jumpinjackie
Copy link
Owner

@copilot There is another corner case cropping up. I have an appdef with 3 maps.

  1. Sheboygan (default)
  2. Redding
  3. Melbourne

The corner case crops up as follows:

  1. Load the map. I get Sheboygan (default)
  2. Switch to Redding. I get its map
  3. Switch to Melbourne. I get its map.
  4. Switch to Redding. I get Redding's map again.
  5. Browser refresh.

Expect: I get Redding's map again.
Get: Something clearly fails in init, because I get a blank map with "Loading..." text.

Screenshot_20260315_024559

…ct map on refresh

Co-authored-by: jumpinjackie <563860+jumpinjackie@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 14, 2026

@copilot There is another corner case cropping up. I have an appdef with 3 maps.

  1. Sheboygan (default)
    ...

The root cause was that the previous fix always deferred non-first (by appdef position) maps to pendingMapDefs, but when Redding was the active map at refresh time, it was "non-first" and got deferred — leaving the active map without a runtimeMap.

Fixed in b62a7d0: createRuntimeMapsAsync now reads this.options.initialActiveMap (populated from the ?map= URL param that records which map was active before refresh) to identify which map to eagerly recover via tryDescribeRuntimeMapAsync. All other maps are still deferred. If initialActiveMap is absent or doesn't match any map in the appdef, it falls back to recovering the first map by position.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • storybook.js.org
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node /home/REDACTED/work/mapguide-react-layout/mapguide-react-layout/node_modules/.bin/storybook build -c .storybook (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Fix browser refresh corner case in multi-map lazy init (issue #1384) Fix browser refresh corner cases in multi-map lazy init (issue #1384) Mar 14, 2026
@jumpinjackie jumpinjackie marked this pull request as ready for review March 14, 2026 17:30
@jumpinjackie jumpinjackie merged commit 18ef117 into master Mar 14, 2026
3 checks passed
@jumpinjackie jumpinjackie deleted the copilot/fix-corner-case-issue-1384 branch March 14, 2026 17:33
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.

3 participants