Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend integration guide: preloading dynamic entry points? #16598

Closed
2 of 4 tasks
mindplay-dk opened this issue May 4, 2024 · 4 comments · Fixed by #16620
Closed
2 of 4 tasks

Backend integration guide: preloading dynamic entry points? #16598

mindplay-dk opened this issue May 4, 2024 · 4 comments · Fixed by #16620
Labels
documentation Improvements or additions to documentation

Comments

@mindplay-dk
Copy link

Documentation is

  • Missing
  • Outdated
  • Confusing
  • Not sure?

Explain in Detail

Following the backend integration guide, I've written a Composer package for vanilla PHP integration, and I hope you can clarify something from the example in the documentation here.

My question is regarding the example near the end of the page:

While the following should be included for the entry point `views/foo.js`:
```html
<link rel="stylesheet" href="assets/shared.a834bfc3.css" />
<script type="module" src="assets/foo.869aea0d.js"></script>
<!-- optional -->
<link rel="modulepreload" href="assets/shared.83069a53.js" />
```

The example manifest.json on this page shows views/foo.js being a dynamic entry:

"views/foo.js": {
"file": "assets/foo.869aea0d.js",
"src": "views/foo.js",
"isDynamicEntry": true,
"imports": ["_shared.83069a53.js"]
},

My question is, when or why would you be preloading a dynamic entry?

To the best of my understanding, a dynamic is loaded dynamically - which, as I understand it, would mean you're not emitting tags on a page, but rather loading the script with an await import statement somewhere in the main script?

Is there any real world use case for an entry with isDynamicEntry to be (pre) loaded on a page?

If this is an error, I might prefer for my package to throw an exception for this case.

Your Suggestion for Changes

The page may need some clarification per my question above. Not sure. 🙂

Reproduction

No response

Steps to reproduce

No response

@mindplay-dk mindplay-dk added the documentation Improvements or additions to documentation label May 4, 2024
@hi-ogawa
Copy link
Collaborator

hi-ogawa commented May 7, 2024

This documentation was expanded recently #16086 and probably what's intended there was multi entry point (pages) scenarios like:

       rollupOptions: {
         input: ['main.js', 'views/foo.js', ...],
       }

So, you put <script main.js /> when SSR-ing "main" page and put <script foo.js /> when SSR-ing "foo" page (and actually this case is not just preload, but executing foo.js).

What looks confusing is that .vite/manifest.json still has main.js --(dynamic import)--> views/foo.js, but this might be an artifact from previous doc.

Technically this situation might be possible if "main" page dynamically loads "foo" page on client side like SPA, but explaining all this might be beyond the simple doc.

@mindplay-dk
Copy link
Author

But using e.g. input: ['main.js', 'views/foo.js'] wouldn't produce a chunk for views/foo.js with isDynamicEntry - but rather isEntry.

The example doesn't show the configuration that was used, so one would have to assume e.g. input: ['main.js'] without views/foo.js - and, one would assume, the views/foo.js chunk must then have come from an await import statement in main.js.

And one would not (I assume?) actually render tags for a dynamic entry on a page?

Rendering tags would always start from an isEntry chunk, would it not?

Still trying to understand if my library should throw an exception if you attempt to create tags for a chunk that is not an entry point. 😵‍💫

@sapphi-red
Copy link
Member

sapphi-red commented May 7, 2024

It was in an inconsistent state. I made a PR to fix that: #16620
Would you check if it doesn't have any confusing parts?

when or why would you be preloading a dynamic entry?

There aren't any cases unless that chunk is also a entry. For example, in this repro (https://stackblitz.com/edit/vitejs-vite-nfbzrw?file=vite.config.js&terminal=dev) counter.js is an entry and a dynamic entry.

Rendering tags would always start from an isEntry chunk, would it not?

Yes. That's correct.

@mindplay-dk
Copy link
Author

Rendering tags would always start from an isEntry chunk, would it not?

Yes. That's correct.

@sapphi-red thank You for the clarification. 🙂

I think that settles the issue, so I will close this.

@hi-ogawa thank you as well 🙂

mindplay-dk added a commit to mindplay-dk/php-vite that referenced this issue May 7, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants