Skip to content

Conversation

@masenf
Copy link
Collaborator

@masenf masenf commented Jan 7, 2026

Pass context={"sitemap": None} to app.add_page to exclude the page from the generated sitemap.

Pass `context={"sitemap": None}` to app.add_page to exclude the page from the
generated sitemap.
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 7, 2026

Merging this PR will not alter performance

Summary

✅ 8 untouched benchmarks


Comparing masenf/sitemap-opt-out (2135a47) with main (89f3a27)

Open in CodSpeed

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 7, 2026

Greptile Summary

Added opt-out functionality for sitemap generation by allowing pages to pass context={"sitemap": None} to app.add_page. The implementation properly handles type narrowing by checking for explicit None values before processing sitemap configuration, maintaining backward compatibility with existing pages that don't specify sitemap configuration.

  • Updated type annotation for sitemap_config from SitemapLinkConfiguration to SitemapLinkConfiguration | None to allow None values
  • Added early return when sitemap_config is None to exclude pages from sitemap generation
  • Type safety is maintained through Python's type narrowing after the None check
  • Backward compatible: pages without sitemap context (context={}) or with empty sitemap config (context={"sitemap": {}}) continue to be included in the sitemap with default settings
  • Comprehensive test case validates both opt-out and default inclusion behaviors

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is clean, type-safe, and well-tested. The change is minimal and focused, adding only 4 lines of code to enable opt-out functionality. Type narrowing ensures no None values are passed to functions expecting non-None configs. The test coverage is comprehensive, validating both the new opt-out behavior and maintaining backward compatibility. No breaking changes or edge cases detected.
  • No files require special attention

Important Files Changed

Filename Overview
reflex/plugins/sitemap.py Added type-safe opt-out mechanism for sitemap inclusion by checking for explicit None values
tests/units/plugins/test_sitemap.py Added comprehensive test case validating that pages with sitemap=None are excluded while default pages are included

Sequence Diagram

sequenceDiagram
    participant App as Reflex App
    participant Plugin as SitemapPlugin
    participant Gen as generate_links_for_sitemap
    participant Config as configuration_with_loc
    participant XML as generate_xml
    
    App->>Plugin: pre_compile(unevaluated_pages)
    Plugin->>Gen: sitemap_task(unevaluated_pages)
    
    loop For each page
        Gen->>Gen: page.context.get("sitemap", {})
        
        alt sitemap is None
            Gen->>Gen: skip page (opt-out)
        else sitemap exists
            alt is dynamic/404 route
                alt no config or no loc
                    Gen->>Gen: skip page or warn
                else has loc
                    Gen->>Config: configuration_with_loc(config, deploy_url, loc)
                    Config-->>Gen: SitemapLink
                end
            else static route
                alt has custom loc
                    Gen->>Config: configuration_with_loc(config, deploy_url, loc)
                    Config-->>Gen: SitemapLink
                else use default route
                    Gen->>Config: configuration_with_loc(config, deploy_url, route)
                    Config-->>Gen: SitemapLink
                end
            end
        end
    end
    
    Gen-->>Plugin: list[SitemapLink]
    Plugin->>XML: generate_xml(links)
    XML-->>Plugin: XML string
    Plugin->>App: save to public/sitemap.xml
Loading

@adhami3310 adhami3310 merged commit beaa713 into main Jan 7, 2026
48 checks passed
@adhami3310 adhami3310 deleted the masenf/sitemap-opt-out branch January 7, 2026 18:58
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