Skip to content

fix: handle live import declaration changes in lazy loader#1192

Merged
joerdav merged 11 commits intoa-h:mainfrom
prathshenoy:sync
Jun 24, 2025
Merged

fix: handle live import declaration changes in lazy loader#1192
joerdav merged 11 commits intoa-h:mainfrom
prathshenoy:sync

Conversation

@prathshenoy
Copy link
Copy Markdown
Contributor

@prathshenoy prathshenoy commented Jun 12, 2025

Note: To support this change, we refactored the existing lazy loader, including moving it into its own internal package. Please let me know if the PR feels too large to review; I’m happy to split it up. That said, most of the diff is from unit tests; the actual logic changes are minimal.

Synchronize the lazy loader with changes to the import section of a templ file. When the imports in a file change (e.g. new or removed dependencies), we now correctly:

  • Detect additions to the import graph and open new packages and their transitive dependencies if necessary
  • Detect removals and close packages that are no longer required

This ensures that the loader maintains a consistent set of open templ files in response to live edits to import declarations, and avoids broken import-related bugs.

@prathshenoy prathshenoy changed the title fix: Handle live import declaration changes in lazy loader fix: handle live import declaration changes in lazy loader Jun 12, 2025
@prathshenoy prathshenoy marked this pull request as ready for review June 14, 2025 00:59
@prathshenoy
Copy link
Copy Markdown
Contributor Author

@joerdav @a-h Could we please get a review of this? We're hoping to get this rolled out by the end of this month. More than happy to discuss any additional details if necessary. Thanks again!

Copy link
Copy Markdown
Collaborator

@joerdav joerdav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a very small nit, but besides that it looks good to me. I tested this out on my small bazel project, but I assume you guys have done some testing too?

@prathshenoy
Copy link
Copy Markdown
Contributor Author

Thanks for the review! We've done thorough testing internally. Were you able to get it working on your Bazel project?

This works well for us, and while there are performance optimizations we could make, our current focus is just getting something functional 🙂.

@joerdav
Copy link
Copy Markdown
Collaborator

joerdav commented Jun 24, 2025

Yes thanks, appears to be working on my example Bazel project. I get completions once when a new import is added.

@joerdav joerdav merged commit f9f9f3a into a-h:main Jun 24, 2025
5 checks passed
@prathshenoy prathshenoy deleted the sync branch June 24, 2025 13:45
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