Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Svelte: inject into primary app.html#63088

Merged
camdencheek merged 1 commit into
mainfrom
cc/svelte-analytics-inverted
Jun 6, 2024
Merged

Svelte: inject into primary app.html#63088
camdencheek merged 1 commit into
mainfrom
cc/svelte-analytics-inverted

Conversation

@camdencheek

@camdencheek camdencheek commented Jun 4, 2024

Copy link
Copy Markdown
Member

This modifies our pattern for shipping a svelte-enabled HTML document by injecting the svelte-specific things into our primary app.html rather than trying to make app.prod.html match the behavior of the frontend app.html.

I could not figure out a "blessed" way to integrate this into the build system, so I went for the hacky way: render app.prod.html in a format that's easily parseable, then parse it in frontend and inject it into our app.html with the standard go template patterns.

Fixes SRCH-76

Test plan

Manual testing with sg start enterprise and sg start enterprise-sveltekit. Manual inspection of the generated HTML and diffing against the previously generated HTML.

@cla-bot cla-bot Bot added the cla-signed label Jun 4, 2024
Comment thread client/web-sveltekit/src/app.prod.html Outdated
Comment on lines 1 to 9

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Instead of trying to reproduce everything that's in the frontend app.html, instead we can build this to be easily parseable and inject it into app.html using Go's templating that we already use heavily.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Related: this PR is an alternative to my earlier draft in which I manually reconciled the two templates. I think this is a generally better approach since we don't need to try to keep those files in sync.

Comment thread sg.config.yaml Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Now that injecting the right application logic is fully the responsibility of frontend, we don't need these sets anymore. sg start enterprise works just fine with the feature flags and switching back and forth.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure that's true. The SvelteKit app still has to be built. If you've built them before then they might or might not be already in the system, but they wouldn't be updated if you e.g. make changes (which doesn't work reliably with these commands either tbf).
That's really the main difference with these commands: They additionally start the build process for the SvelteKit web app. How the HTML file is generated is irrelevant.

@camdencheek camdencheek Jun 6, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

(which doesn't work reliably with these commands either tbf).

Ah, gotcha. I was always under the impression that I had to build manually for these commands to work. Okay, I'll roll back these changes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It might be fine to remove them. I don't think the rebuilding actually works. The process often terminates. In other words it doesn't really work reliably.

@camdencheek camdencheek Jun 6, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, okay, unreverting then 🙂 I think we should probably build sveltekit by default with sg start enterprise at this point. I'll work on that as a followup

Comment thread cmd/frontend/internal/app/ui/app.html Outdated
Comment thread client/web/dev/esbuild/server.ts Outdated
Comment on lines 41 to 54

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This seemed to only be used by sg start enterprise-sveltekit, which no longer exists now that we use the same app.html for everything. I think this could still be used to run a dev server with a local instance, but I think it's probably more intuitive to just run pnpm dev with an overriden SOURCEGRAPH_API_URL. Am I off base here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See my comment below. I believe to remember that I added this separately because otherwise the request would be handled by the esbuild web server, which will trigger a rebuild of the react app (unnecessarily) which is rather slow (comparatively).

@camdencheek camdencheek force-pushed the cc/svelte-analytics-inverted branch from b127eea to 273aff0 Compare June 5, 2024 18:45
@camdencheek camdencheek force-pushed the cc/svelte-analytics-inverted branch from 273aff0 to 4d00aba Compare June 5, 2024 18:50
@camdencheek camdencheek marked this pull request as ready for review June 5, 2024 19:08
@camdencheek camdencheek requested review from a team and fkling June 5, 2024 19:14
Comment thread cmd/frontend/internal/app/ui/app.html Outdated
Comment on lines -330 to -333
if sveltekit.Enabled(r.Context()) {
return sveltekit.RenderTemplate(w, common)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This makes me very happy. I always thought it would be nice to eventually do the switch in renderTemplate so that it "just works" everywhere.

Comment thread sg.config.yaml Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure that's true. The SvelteKit app still has to be built. If you've built them before then they might or might not be already in the system, but they wouldn't be updated if you e.g. make changes (which doesn't work reliably with these commands either tbf).
That's really the main difference with these commands: They additionally start the build process for the SvelteKit web app. How the HTML file is generated is irrelevant.

Comment thread client/web/dev/esbuild/server.ts Outdated
Comment on lines 41 to 54

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See my comment below. I believe to remember that I added this separately because otherwise the request would be handled by the esbuild web server, which will trigger a rebuild of the react app (unnecessarily) which is rather slow (comparatively).

@camdencheek camdencheek force-pushed the cc/svelte-analytics-inverted branch from 488d197 to 4d00aba Compare June 6, 2024 14:36
@camdencheek

Copy link
Copy Markdown
Member Author

@fkling were there any followups you were looking for from your comments?

@camdencheek camdencheek merged commit 8f4a610 into main Jun 6, 2024
@camdencheek camdencheek deleted the cc/svelte-analytics-inverted branch June 6, 2024 15:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants