jlaneve opened a new pull request, #74777:
URL: https://github.com/apache/airflow/pull/74777

   A React plugin with `destination: "base"` renders on every page, but the UI 
learns its bundle URL only from `GET /api/v2/plugins`, after the UI's own 
scripts have run. On a Fast 3G profile the browser starts the bundle download 
11.3 s into the page load, so the plugin shows up late and the page moves down. 
The server now adds a `modulepreload` link to `index.html` for each base app's 
bundle, and the browser starts the download 0.2 s into the load. The UI's later 
`import()` of the same URL takes the preloaded module, so the bundle still 
downloads once.
   
   ## Call-stack diff
   
   ```diff
     GET /{rest_of_path}                       core_api/app.py
     └─ webapp()
        └─ TemplateResponse("/index.html")
           ├─ backend_server_base_url          # unchanged
   +       └─ preload_bundle_urls              # computed once in init_views
   +          └─ base_react_app_bundle_urls()
   +             └─ get_plugin_info(["react_apps"])  # base apps, no team
   
     index.html
        <base href>                            # unchanged
   +    <link rel="modulepreload" href>        # one per base bundle
   ```
   
   Unchanged: `ReactPlugin` still loads the bundle with `import()` and resolves 
the URL against `document.baseURI`. The `<link>` follows `<base>`, so both 
resolve to the same URL.
   
   - **Where I am least sure.** The page is rendered before the server knows 
the user, so it can't apply the checks `GET /api/v2/plugins` makes. I left out 
team-scoped plugins, because that endpoint hides them from users outside the 
team. A user without the plugins view permission still gets the preload link 
for a global base plugin and downloads a bundle the UI never imports. If that 
matters, the other option is to read the user from the request here.
   - **What it cost.** I measured with the Astro Bar on Runtime 3.3.1, cache 
disabled, median of 5 loads, with the link added to the built `index.html`. On 
Fast 3G the bar appeared 0.8 s after the page instead of 1.3 s. On Fast 4G 
nothing changed (0.8 s both ways), because the remaining wait is the plugins 
request and the plugin's own API calls. The page itself rendered no later.
   - **What is not here.** Reserving a remembered height, the other idea from 
#74762. It helps only a base plugin at the top of the page.
   
   Related: #74762
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code (Claude Opus 5.5) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   ---
   
   * Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
 for more information. Note: commit author/co-author name and email in commits 
become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal 
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
 is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License 
Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: 
`{pr_number}.significant.rst`, in 
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
 You can add this file in a follow-up commit after the PR is created so you 
know the PR number.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to